diff --git a/cmd/httpserver/AccountAction.go b/cmd/httpserver/AccountAction.go index 6001a8d..b8aabe6 100644 --- a/cmd/httpserver/AccountAction.go +++ b/cmd/httpserver/AccountAction.go @@ -14,31 +14,39 @@ type AccountAction struct { HttpServer *AccountServer } -func (h *AccountAction) Register(c *gin.Context) (int, interface{}){ +func (h *AccountAction) Register(c *gin.Context) (int, interface{}) { var register pb.Register if err := c.ShouldBindJSON(®ister); err != nil { return 1, err.Error() } - if register.Code != "0000" { + key := fmt.Sprintf(common.SMSCode, register.Phone) + + relay, err := redisproxy.GET(key) + if err != nil { + return 2, err.Error() + } + code := relay.(string) + + if register.Code != code { return 2, "code error" } account := models.NewAccount(register.Phone) if err := account.Load(); err == nil { - return 3 , "account exists: " + register.Phone + return 3, "account exists: " + register.Phone } account.Uid = common.SnowFlack.NextValStr() account.Password = common.Md5V(register.Password) - if err := account.Create(); err != nil{ + if err := account.Create(); err != nil { return 4, "account register err: " + err.Error() } account.Password = register.Password return 0, "success" } -func (h *AccountAction) Login(c *gin.Context) (int,interface{}) { +func (h *AccountAction) Login(c *gin.Context) (int, interface{}) { var login pb.Account if err := c.ShouldBindJSON(&login); err != nil { return 1, err.Error() @@ -61,13 +69,13 @@ func (h *AccountAction) Login(c *gin.Context) (int,interface{}) { }) } rsp := &pb.LoginRsp{ - Token: account.Uid, + Token: account.Uid, GameService: gs, } return 0, rsp } -func (h *AccountAction) Sms(c *gin.Context) (int,interface{}) { +func (h *AccountAction) Sms(c *gin.Context) (int, interface{}) { c.Request.ParseForm() phone, ok := c.GetPostForm("phone") if !ok { @@ -90,4 +98,3 @@ func (h *AccountAction) Sms(c *gin.Context) (int,interface{}) { return 0, nil } - -- libgit2 0.21.2