作者 yangfu

user auth fix

@@ -50,6 +50,16 @@ type UCenterGetUserResponse struct { @@ -50,6 +50,16 @@ type UCenterGetUserResponse struct {
50 CustomerAccount int64 `json:"customerAccount"` 50 CustomerAccount int64 `json:"customerAccount"`
51 } 51 }
52 52
  53 +type UCenter_GetUserResponse struct {
  54 + Id int64 `json:"id"`
  55 + Phone string `json:"phone"`
  56 + NickName string `json:"nickname"`
  57 + Avatar string `json:"avatar"`
  58 + ImToken string `json:"imtoken"`
  59 + Accid string `json:"accid"`
  60 + CustomerAccount string `json:"customerAccount"`
  61 +}
  62 +
53 /*修改用户信息 UCenterPutUser */ 63 /*修改用户信息 UCenterPutUser */
54 type UCenterPutUserRequest struct { 64 type UCenterPutUserRequest struct {
55 Phone string `json:"phone,omitempty"` 65 Phone string `json:"phone,omitempty"`
@@ -260,7 +260,7 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe @@ -260,7 +260,7 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
260 userAuth *models.UserAuth 260 userAuth *models.UserAuth
261 ) 261 )
262 if len(request.Token) == 0 { 262 if len(request.Token) == 0 {
263 - err = common.NewErrorWithMsg(4141, "token not empty") 263 + err = protocol.NewErrWithMessage(4141)
264 return 264 return
265 } 265 }
266 userAuth, err = models.GetUserAuthByToken(request.Token) 266 userAuth, err = models.GetUserAuthByToken(request.Token)
@@ -371,7 +371,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) { @@ -371,7 +371,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) {
371 ) 371 )
372 result = false 372 result = false
373 if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode 373 if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode
374 - log.Error(fmt.Sprintf("smscode not exists")) 374 + log.Error(fmt.Sprintf("%v smscode not exists", phone))
375 err = protocol.NewErrWithMessage(1009, fmt.Errorf("smscode expire")) 375 err = protocol.NewErrWithMessage(1009, fmt.Errorf("smscode expire"))
376 return 376 return
377 } 377 }
@@ -25,7 +25,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode @@ -25,7 +25,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode
25 log.Error(err) 25 log.Error(err)
26 return 26 return
27 } 27 }
28 - if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil { 28 + if result, err = auth.CheckSmsCode(strings.TrimSpace(user.Phone), request.Captcha, protocol.SmsCode); err != nil {
29 log.Error(err) 29 log.Error(err)
30 return 30 return
31 } 31 }
@@ -50,10 +50,10 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe @@ -50,10 +50,10 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
50 return 50 return
51 } 51 }
52 //判断库里面是否已经有这个手机号的用户 52 //判断库里面是否已经有这个手机号的用户
53 - //if _, err = repository.User.GetUsersByMobile(request.Phone); err == nil {  
54 - // err = protocol.NewErrWithMessage(2029)  
55 - // return  
56 - //} 53 + if _, err = models.GetUserByMobile(request.Phone); err == nil {
  54 + err = protocol.NewErrWithMessage(2029)
  55 + return
  56 + }
57 if !result { 57 if !result {
58 err = protocol.NewErrWithMessage(1012) 58 err = protocol.NewErrWithMessage(1012)
59 return 59 return
@@ -85,7 +85,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo @@ -85,7 +85,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
85 user *models.User 85 user *models.User
86 message *protocol.Message 86 message *protocol.Message
87 getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{} 87 getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{}
88 - getUserResponse *protocol.UCenterGetUserResponse 88 + getUserResponse *protocol.UCenter_GetUserResponse
89 result bool 89 result bool
90 ) 90 )
91 if len(request.NewPwd) < 6 { 91 if len(request.NewPwd) < 6 {
@@ -117,6 +117,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo @@ -117,6 +117,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
117 } else { 117 } else {
118 err = protocol.NewErrWithMessage(1) 118 err = protocol.NewErrWithMessage(1)
119 log.Error("用户中心获取数据失败: err_no:%v msg:%v", message.Errno, message.Errmsg) 119 log.Error("用户中心获取数据失败: err_no:%v msg:%v", message.Errno, message.Errmsg)
  120 + return
120 } 121 }
121 if getUserResponse.Id != user.UserCenterId { 122 if getUserResponse.Id != user.UserCenterId {
122 err = protocol.NewErrWithMessage(1) 123 err = protocol.NewErrWithMessage(1)
@@ -152,8 +153,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass @@ -152,8 +153,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
152 } 153 }
153 var message protocol.Message 154 var message protocol.Message
154 if _, err = agg.RequestUserCenter(protocol.MethodLogin, http.MethodPost, &protocol.UCenterLoginRequest{ 155 if _, err = agg.RequestUserCenter(protocol.MethodLogin, http.MethodPost, &protocol.UCenterLoginRequest{
155 - PassWord: request.OldPwd,  
156 - Phone: user.Phone, 156 + PassWord: request.OldPwd,
  157 + Phone: user.Phone,
  158 + Type: 1,
  159 + GrantType: protocol.LoginTypePassPord,
157 }, &message); err != nil { 160 }, &message); err != nil {
158 log.Error(err) 161 log.Error(err)
159 return 162 return