Commit 944a2ef6071f88eb6b948b8dc9c8a195039d0006
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 | 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 | 18 | var register pb.Register |
| 19 | 19 | if err := c.ShouldBindJSON(®ister); err != nil { |
| 20 | 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 | 32 | return 2, "code error" |
| 25 | 33 | } |
| 26 | 34 | |
| 27 | 35 | account := models.NewAccount(register.Phone) |
| 28 | 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 | 40 | account.Uid = common.SnowFlack.NextValStr() |
| 33 | 41 | account.Password = common.Md5V(register.Password) |
| 34 | - if err := account.Create(); err != nil{ | |
| 42 | + if err := account.Create(); err != nil { | |
| 35 | 43 | return 4, "account register err: " + err.Error() |
| 36 | 44 | } |
| 37 | 45 | account.Password = register.Password |
| 38 | 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 | 50 | var login pb.Account |
| 43 | 51 | if err := c.ShouldBindJSON(&login); err != nil { |
| 44 | 52 | return 1, err.Error() |
| ... | ... | @@ -61,13 +69,13 @@ func (h *AccountAction) Login(c *gin.Context) (int,interface{}) { |
| 61 | 69 | }) |
| 62 | 70 | } |
| 63 | 71 | rsp := &pb.LoginRsp{ |
| 64 | - Token: account.Uid, | |
| 72 | + Token: account.Uid, | |
| 65 | 73 | GameService: gs, |
| 66 | 74 | } |
| 67 | 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 | 79 | c.Request.ParseForm() |
| 72 | 80 | phone, ok := c.GetPostForm("phone") |
| 73 | 81 | if !ok { |
| ... | ... | @@ -90,4 +98,3 @@ func (h *AccountAction) Sms(c *gin.Context) (int,interface{}) { |
| 90 | 98 | |
| 91 | 99 | return 0, nil |
| 92 | 100 | } |
| 93 | - | ... | ... |