作者 陈志颖

feat:增加短信验证码验证

... ... @@ -21,8 +21,8 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
}
func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone)
errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone)
errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) // 合伙人修改手机号
errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) // 高管修改手机号
return errResolve(errPartner, errManager)
}
func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
... ...
... ... @@ -2,9 +2,11 @@ package controllers
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"strings"
"time"
)
type UserController struct {
... ... @@ -61,10 +63,15 @@ func (this *UserController) CheckSmsCode() {
**/
func (this *UserController) ChangePhone() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChangePhoneRequest
header := this.GetRequestHeader(this.Ctx)
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
... ... @@ -73,21 +80,42 @@ func (this *UserController) ChangePhone() {
msg = m
return
}
if !CacheSms.IsExist(request.OldPhone) {
// 校验短信验证码
var authCheckSmsCodeRequest *protocol.AuthCheckSmsCodeRequest
if err := this.JsonUnmarshal(&authCheckSmsCodeRequest); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(authCheckSmsCodeRequest); !b {
msg = m
return
}
rsp, err := auth.AuthCheckSmsCode(header, authCheckSmsCodeRequest)
if err != nil {
msg = protocol.NewReturnResponse(rsp, err)
return
}
err = CacheSms.Put(request.Phone, rsp.CaptchaCertificate, 5*time.Minute)
if err != nil {
msg = protocol.NewReturnResponse(rsp, err)
return
}
if !CacheSms.IsExist(request.Phone) {
msg = protocol.NewMesage(1009) //验证码失效
return
}
// TODO ?
//if v := CacheSms.Get(request.OldPhone); v != nil {
// if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {
// msg = protocol.NewMesage(1012) //验证码不一致
// return
// }
//} else {
// msg = protocol.NewMesage(1009) //验证码不一致
// return
//}
header := this.GetRequestHeader(this.Ctx)
if v := CacheSms.Get(request.Phone); v != nil {
//if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {
// msg = protocol.NewMesage(1012) //验证码不一致
// return
//}
} else {
msg = protocol.NewMesage(1009) //验证码不一致
return
}
data, err := user.ChangePhone(header, request)
if err == nil {
msg = protocol.NewResponseMessage(0, "修改手机号成功")
... ...