作者 yangfu

user auth fix

... ... @@ -50,6 +50,16 @@ type UCenterGetUserResponse struct {
CustomerAccount int64 `json:"customerAccount"`
}
type UCenter_GetUserResponse struct {
Id int64 `json:"id"`
Phone string `json:"phone"`
NickName string `json:"nickname"`
Avatar string `json:"avatar"`
ImToken string `json:"imtoken"`
Accid string `json:"accid"`
CustomerAccount string `json:"customerAccount"`
}
/*修改用户信息 UCenterPutUser */
type UCenterPutUserRequest struct {
Phone string `json:"phone,omitempty"`
... ...
... ... @@ -260,7 +260,7 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
userAuth *models.UserAuth
)
if len(request.Token) == 0 {
err = common.NewErrorWithMsg(4141, "token not empty")
err = protocol.NewErrWithMessage(4141)
return
}
userAuth, err = models.GetUserAuthByToken(request.Token)
... ... @@ -371,7 +371,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) {
)
result = false
if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode
log.Error(fmt.Sprintf("smscode not exists"))
log.Error(fmt.Sprintf("%v smscode not exists", phone))
err = protocol.NewErrWithMessage(1009, fmt.Errorf("smscode expire"))
return
}
... ...
... ... @@ -25,7 +25,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode
log.Error(err)
return
}
if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil {
if result, err = auth.CheckSmsCode(strings.TrimSpace(user.Phone), request.Captcha, protocol.SmsCode); err != nil {
log.Error(err)
return
}
... ... @@ -50,10 +50,10 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
return
}
//判断库里面是否已经有这个手机号的用户
//if _, err = repository.User.GetUsersByMobile(request.Phone); err == nil {
// err = protocol.NewErrWithMessage(2029)
// return
//}
if _, err = models.GetUserByMobile(request.Phone); err == nil {
err = protocol.NewErrWithMessage(2029)
return
}
if !result {
err = protocol.NewErrWithMessage(1012)
return
... ... @@ -85,7 +85,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
user *models.User
message *protocol.Message
getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{}
getUserResponse *protocol.UCenterGetUserResponse
getUserResponse *protocol.UCenter_GetUserResponse
result bool
)
if len(request.NewPwd) < 6 {
... ... @@ -117,6 +117,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
} else {
err = protocol.NewErrWithMessage(1)
log.Error("用户中心获取数据失败: err_no:%v msg:%v", message.Errno, message.Errmsg)
return
}
if getUserResponse.Id != user.UserCenterId {
err = protocol.NewErrWithMessage(1)
... ... @@ -154,6 +155,8 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
if _, err = agg.RequestUserCenter(protocol.MethodLogin, http.MethodPost, &protocol.UCenterLoginRequest{
PassWord: request.OldPwd,
Phone: user.Phone,
Type: 1,
GrantType: protocol.LoginTypePassPord,
}, &message); err != nil {
log.Error(err)
return
... ...