|
|
package user
|
|
|
|
|
|
//import
|
|
|
//(
|
|
|
// "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
|
|
|
// "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
// "opp/models"
|
|
|
//)
|
|
|
//
|
|
|
//func GetUserList(mobile string)*protocol.ResponseMessage{
|
|
|
// u,err:=models.GetUserByMobile(mobile)
|
|
|
// if err!=nil{
|
|
|
// log.Error(err)
|
|
|
// log.Error(mobile)
|
|
|
// return mybeego.NewErrMessage(1)
|
|
|
// }
|
|
|
// msg :=protocol.ReturnResponse(0)
|
|
|
// msg.Data = u
|
|
|
// return msg
|
|
|
//} |
|
|
import (
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
"opp/internal/repository"
|
|
|
"opp/internal/utils"
|
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"opp/services/auth"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
//验证smscode
|
|
|
func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCodeRequest) (rsp *protocol.CheckSmsCodeResponse, err error) {
|
|
|
var (
|
|
|
user *models.User
|
|
|
result bool
|
|
|
)
|
|
|
//rsp =&protocol.CheckSmsCodeResponse{}
|
|
|
|
|
|
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if !result {
|
|
|
err = protocol.NewErrWithMessage(1012)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//修改手机号
|
|
|
func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) {
|
|
|
var (
|
|
|
user *models.User
|
|
|
result bool
|
|
|
)
|
|
|
//rsp =&protocol.ChangePhoneResponse{}
|
|
|
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if !result {
|
|
|
err = protocol.NewErrWithMessage(1012)
|
|
|
}
|
|
|
err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Phone": request.Phone})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//重置密码
|
|
|
func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
|
|
|
var (
|
|
|
user *models.User
|
|
|
)
|
|
|
//rsp =&protocol.ResetPasswordResponse{}
|
|
|
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
//TODO:未验证 校验码
|
|
|
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
|
|
|
err = protocol.NewErrWithMessage(2026)
|
|
|
}
|
|
|
err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//修改密码
|
|
|
func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) {
|
|
|
var (
|
|
|
user *models.User
|
|
|
)
|
|
|
//rsp =&protocol.ChangePasswordResponse{}
|
|
|
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if strings.EqualFold(request.OldPwd, user.Passwd) {
|
|
|
err = protocol.NewErrWithMessage(1)
|
|
|
}
|
|
|
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
|
|
|
err = protocol.NewErrWithMessage(2026)
|
|
|
}
|
|
|
err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd})
|
|
|
return
|
|
|
} |
...
|
...
|
|