作者 陈志颖

feat:增加短信验证码验证

@@ -21,8 +21,8 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService { @@ -21,8 +21,8 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
21 } 21 }
22 22
23 func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) { 23 func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
24 - errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone)  
25 - errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) 24 + errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) // 合伙人修改手机号
  25 + errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) // 高管修改手机号
26 return errResolve(errPartner, errManager) 26 return errResolve(errPartner, errManager)
27 } 27 }
28 func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) { 28 func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
@@ -2,9 +2,11 @@ package controllers @@ -2,9 +2,11 @@ package controllers
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
7 "strings" 8 "strings"
  9 + "time"
8 ) 10 )
9 11
10 type UserController struct { 12 type UserController struct {
@@ -61,10 +63,15 @@ func (this *UserController) CheckSmsCode() { @@ -61,10 +63,15 @@ func (this *UserController) CheckSmsCode() {
61 **/ 63 **/
62 func (this *UserController) ChangePhone() { 64 func (this *UserController) ChangePhone() {
63 var msg *protocol.ResponseMessage 65 var msg *protocol.ResponseMessage
  66 +
64 defer func() { 67 defer func() {
65 this.Resp(msg) 68 this.Resp(msg)
66 }() 69 }()
  70 +
67 var request *protocol.ChangePhoneRequest 71 var request *protocol.ChangePhoneRequest
  72 +
  73 + header := this.GetRequestHeader(this.Ctx)
  74 +
68 if err := this.JsonUnmarshal(&request); err != nil { 75 if err := this.JsonUnmarshal(&request); err != nil {
69 msg = protocol.BadRequestParam(1) 76 msg = protocol.BadRequestParam(1)
70 return 77 return
@@ -73,21 +80,42 @@ func (this *UserController) ChangePhone() { @@ -73,21 +80,42 @@ func (this *UserController) ChangePhone() {
73 msg = m 80 msg = m
74 return 81 return
75 } 82 }
76 - if !CacheSms.IsExist(request.OldPhone) { 83 +
  84 + // 校验短信验证码
  85 + var authCheckSmsCodeRequest *protocol.AuthCheckSmsCodeRequest
  86 + if err := this.JsonUnmarshal(&authCheckSmsCodeRequest); err != nil {
  87 + msg = protocol.BadRequestParam(1)
  88 + return
  89 + }
  90 + if b, m := this.Valid(authCheckSmsCodeRequest); !b {
  91 + msg = m
  92 + return
  93 + }
  94 + rsp, err := auth.AuthCheckSmsCode(header, authCheckSmsCodeRequest)
  95 + if err != nil {
  96 + msg = protocol.NewReturnResponse(rsp, err)
  97 + return
  98 + }
  99 + err = CacheSms.Put(request.Phone, rsp.CaptchaCertificate, 5*time.Minute)
  100 + if err != nil {
  101 + msg = protocol.NewReturnResponse(rsp, err)
  102 + return
  103 + }
  104 +
  105 + if !CacheSms.IsExist(request.Phone) {
77 msg = protocol.NewMesage(1009) //验证码失效 106 msg = protocol.NewMesage(1009) //验证码失效
78 return 107 return
79 } 108 }
80 - // TODO ?  
81 - //if v := CacheSms.Get(request.OldPhone); v != nil {  
82 - // if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) { 109 + if v := CacheSms.Get(request.Phone); v != nil {
  110 + //if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {
83 // msg = protocol.NewMesage(1012) //验证码不一致 111 // msg = protocol.NewMesage(1012) //验证码不一致
84 // return 112 // return
85 - // }  
86 - //} else {  
87 - // msg = protocol.NewMesage(1009) //验证码不一致  
88 - // return  
89 //} 113 //}
90 - header := this.GetRequestHeader(this.Ctx) 114 + } else {
  115 + msg = protocol.NewMesage(1009) //验证码不一致
  116 + return
  117 + }
  118 +
91 data, err := user.ChangePhone(header, request) 119 data, err := user.ChangePhone(header, request)
92 if err == nil { 120 if err == nil {
93 msg = protocol.NewResponseMessage(0, "修改手机号成功") 121 msg = protocol.NewResponseMessage(0, "修改手机号成功")