作者 tangxvhui

短信登录 进行中

@@ -91,16 +91,18 @@ func (c *AuthController) LoginSms() { @@ -91,16 +91,18 @@ func (c *AuthController) LoginSms() {
91 c.ResposeJson(msg) 91 c.ResposeJson(msg)
92 }() 92 }()
93 93
94 - var param protocol.RequestLogin 94 + var param protocol.RequestLoginSms
95 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 95 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
96 log.Error("json 解析失败", err) 96 log.Error("json 解析失败", err)
97 msg = protocol.BadRequestParam("1") 97 msg = protocol.BadRequestParam("1")
98 return 98 return
99 } 99 }
100 - // if len(param.Account) == 0 || len(param.Password) == 0 {  
101 - // msg = protocol.BadRequestParam("10021")  
102 - // return  
103 - // } 100 + if len(param.Account) == 0 || len(param.Code) == 0 {
  101 + msg = protocol.BadRequestParam("10021")
  102 + return
  103 + }
  104 +
  105 + //短信校验接口调用
104 // logintoken, err := serveauth.LoginAuthByUCenter(param.Account, param.Password) 106 // logintoken, err := serveauth.LoginAuthByUCenter(param.Account, param.Password)
105 // if err != nil { 107 // if err != nil {
106 // msg = protocol.NewReturnResponse(nil, err) 108 // msg = protocol.NewReturnResponse(nil, err)
@@ -117,7 +119,29 @@ func (c *AuthController) LoginSms() { @@ -117,7 +119,29 @@ func (c *AuthController) LoginSms() {
117 // data := map[string]interface{}{ 119 // data := map[string]interface{}{
118 // "access": logintoken, 120 // "access": logintoken,
119 // } 121 // }
120 - // msg = protocol.NewReturnResponse(data, nil) 122 + msg = protocol.NewReturnResponse(nil, nil)
  123 + return
  124 +}
  125 +
  126 +func (c *AuthController) SmsCode() {
  127 + var msg *protocol.ResponseMessage
  128 + defer func() {
  129 + c.ResposeJson(msg)
  130 + }()
  131 + type Parameter struct {
  132 + Phone string `json:"phone"`
  133 + }
  134 + var param Parameter
  135 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  136 + log.Error("json 解析失败", err)
  137 + msg = protocol.BadRequestParam("1")
  138 + return
  139 + }
  140 + if len(param.Phone) == 0 {
  141 + msg = protocol.BadRequestParam("1")
  142 + return
  143 + }
  144 + msg = protocol.NewReturnResponse(nil, nil)
121 return 145 return
122 } 146 }
123 147
@@ -160,7 +184,7 @@ func (c *AuthController) ChangeCompany() { @@ -160,7 +184,7 @@ func (c *AuthController) ChangeCompany() {
160 return 184 return
161 } 185 }
162 186
163 -//Me 187 +//Me 。。
164 //@router /me [get] 188 //@router /me [get]
165 func (c *AuthController) Me() { 189 func (c *AuthController) Me() {
166 var msg *protocol.ResponseMessage 190 var msg *protocol.ResponseMessage
@@ -195,6 +219,7 @@ const ( @@ -195,6 +219,7 @@ const (
195 privateKey = "13320fd2b10199e9a2440a4fbb4d46f7" 219 privateKey = "13320fd2b10199e9a2440a4fbb4d46f7"
196 ) 220 )
197 221
  222 +// RegisterGeetest 极验初始化
198 func (c *AuthController) RegisterGeetest() { 223 func (c *AuthController) RegisterGeetest() {
199 geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second) 224 geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
200 userip := c.Ctx.Input.IP() 225 userip := c.Ctx.Input.IP()
@@ -204,6 +229,7 @@ func (c *AuthController) RegisterGeetest() { @@ -204,6 +229,7 @@ func (c *AuthController) RegisterGeetest() {
204 return 229 return
205 } 230 }
206 231
  232 +// RegisterGeetest 极验初校验
207 func (c *AuthController) ValidateGeetest() { 233 func (c *AuthController) ValidateGeetest() {
208 type Parameter struct { 234 type Parameter struct {
209 GeetestChallenge string `form:"geetest_challenge"` 235 GeetestChallenge string `form:"geetest_challenge"`
@@ -26,6 +26,12 @@ type RequestLogin struct { @@ -26,6 +26,12 @@ type RequestLogin struct {
26 Password string `json:"password"` 26 Password string `json:"password"`
27 } 27 }
28 28
  29 +//RequestLoginSms 短信验证登录请求
  30 +type RequestLoginSms struct {
  31 + Account string `json:"account"`
  32 + Code string `json:"code"`
  33 +}
  34 +
29 //ResponseLogin 登录响应 35 //ResponseLogin 登录响应
30 type ResponseLogin struct { 36 type ResponseLogin struct {
31 Access LoginAuthToken `json:"access"` 37 Access LoginAuthToken `json:"access"`
@@ -97,6 +97,8 @@ func init() { @@ -97,6 +97,8 @@ func init() {
97 beego.NSRouter("/login", &controllers.AuthController{}, "post:Login"), 97 beego.NSRouter("/login", &controllers.AuthController{}, "post:Login"),
98 beego.NSRouter("/startCaptcha", &controllers.AuthController{}, "post:RegisterGeetest"), 98 beego.NSRouter("/startCaptcha", &controllers.AuthController{}, "post:RegisterGeetest"),
99 beego.NSRouter("/verifyCaptcha", &controllers.AuthController{}, "post:ValidateGeetest"), 99 beego.NSRouter("/verifyCaptcha", &controllers.AuthController{}, "post:ValidateGeetest"),
  100 + beego.NSRouter("/login_sms", &controllers.AuthController{}, "post:LoginSms"),
  101 + beego.NSRouter("/sms_code", &controllers.AuthController{}, "post:SmsCode"),
100 ) 102 )
101 nsUcenter := beego.NewNamespace("/ucenter", 103 nsUcenter := beego.NewNamespace("/ucenter",
102 beego.NSBefore(middleware.LogRequestData), 104 beego.NSBefore(middleware.LogRequestData),