Commit 944a2ef6071f88eb6b948b8dc9c8a195039d0006

Authored by zhangqijia
1 parent c47aa250

fix: 注册增加验证码,暂时使用拾荒团的短信验证

Showing 1 changed file with 15 additions and 8 deletions   Show diff stats
cmd/httpserver/AccountAction.go
@@ -14,31 +14,39 @@ type AccountAction struct { @@ -14,31 +14,39 @@ type AccountAction struct {
14 HttpServer *AccountServer 14 HttpServer *AccountServer
15 } 15 }
16 16
17 -func (h *AccountAction) Register(c *gin.Context) (int, interface{}){ 17 +func (h *AccountAction) Register(c *gin.Context) (int, interface{}) {
18 var register pb.Register 18 var register pb.Register
19 if err := c.ShouldBindJSON(&register); err != nil { 19 if err := c.ShouldBindJSON(&register); err != nil {
20 return 1, err.Error() 20 return 1, err.Error()
21 } 21 }
22 22
23 - if register.Code != "0000" { 23 + key := fmt.Sprintf(common.SMSCode, register.Phone)
  24 +
  25 + relay, err := redisproxy.GET(key)
  26 + if err != nil {
  27 + return 2, err.Error()
  28 + }
  29 + code := relay.(string)
  30 +
  31 + if register.Code != code {
24 return 2, "code error" 32 return 2, "code error"
25 } 33 }
26 34
27 account := models.NewAccount(register.Phone) 35 account := models.NewAccount(register.Phone)
28 if err := account.Load(); err == nil { 36 if err := account.Load(); err == nil {
29 - return 3 , "account exists: " + register.Phone 37 + return 3, "account exists: " + register.Phone
30 } 38 }
31 39
32 account.Uid = common.SnowFlack.NextValStr() 40 account.Uid = common.SnowFlack.NextValStr()
33 account.Password = common.Md5V(register.Password) 41 account.Password = common.Md5V(register.Password)
34 - if err := account.Create(); err != nil{ 42 + if err := account.Create(); err != nil {
35 return 4, "account register err: " + err.Error() 43 return 4, "account register err: " + err.Error()
36 } 44 }
37 account.Password = register.Password 45 account.Password = register.Password
38 return 0, "success" 46 return 0, "success"
39 } 47 }
40 48
41 -func (h *AccountAction) Login(c *gin.Context) (int,interface{}) { 49 +func (h *AccountAction) Login(c *gin.Context) (int, interface{}) {
42 var login pb.Account 50 var login pb.Account
43 if err := c.ShouldBindJSON(&login); err != nil { 51 if err := c.ShouldBindJSON(&login); err != nil {
44 return 1, err.Error() 52 return 1, err.Error()
@@ -61,13 +69,13 @@ func (h *AccountAction) Login(c *gin.Context) (int,interface{}) { @@ -61,13 +69,13 @@ func (h *AccountAction) Login(c *gin.Context) (int,interface{}) {
61 }) 69 })
62 } 70 }
63 rsp := &pb.LoginRsp{ 71 rsp := &pb.LoginRsp{
64 - Token: account.Uid, 72 + Token: account.Uid,
65 GameService: gs, 73 GameService: gs,
66 } 74 }
67 return 0, rsp 75 return 0, rsp
68 } 76 }
69 77
70 -func (h *AccountAction) Sms(c *gin.Context) (int,interface{}) { 78 +func (h *AccountAction) Sms(c *gin.Context) (int, interface{}) {
71 c.Request.ParseForm() 79 c.Request.ParseForm()
72 phone, ok := c.GetPostForm("phone") 80 phone, ok := c.GetPostForm("phone")
73 if !ok { 81 if !ok {
@@ -90,4 +98,3 @@ func (h *AccountAction) Sms(c *gin.Context) (int,interface{}) { @@ -90,4 +98,3 @@ func (h *AccountAction) Sms(c *gin.Context) (int,interface{}) {
90 98
91 return 0, nil 99 return 0, nil
92 } 100 }
93 -