作者 tangxvhui

短信登录 进行中

... ... @@ -91,16 +91,18 @@ func (c *AuthController) LoginSms() {
c.ResposeJson(msg)
}()
var param protocol.RequestLogin
var param protocol.RequestLoginSms
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
// if len(param.Account) == 0 || len(param.Password) == 0 {
// msg = protocol.BadRequestParam("10021")
// return
// }
if len(param.Account) == 0 || len(param.Code) == 0 {
msg = protocol.BadRequestParam("10021")
return
}
//短信校验接口调用
// logintoken, err := serveauth.LoginAuthByUCenter(param.Account, param.Password)
// if err != nil {
// msg = protocol.NewReturnResponse(nil, err)
... ... @@ -117,7 +119,29 @@ func (c *AuthController) LoginSms() {
// data := map[string]interface{}{
// "access": logintoken,
// }
// msg = protocol.NewReturnResponse(data, nil)
msg = protocol.NewReturnResponse(nil, nil)
return
}
func (c *AuthController) SmsCode() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Phone string `json:"phone"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
if len(param.Phone) == 0 {
msg = protocol.BadRequestParam("1")
return
}
msg = protocol.NewReturnResponse(nil, nil)
return
}
... ... @@ -160,7 +184,7 @@ func (c *AuthController) ChangeCompany() {
return
}
//Me
//Me 。。
//@router /me [get]
func (c *AuthController) Me() {
var msg *protocol.ResponseMessage
... ... @@ -195,6 +219,7 @@ const (
privateKey = "13320fd2b10199e9a2440a4fbb4d46f7"
)
// RegisterGeetest 极验初始化
func (c *AuthController) RegisterGeetest() {
geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
userip := c.Ctx.Input.IP()
... ... @@ -204,6 +229,7 @@ func (c *AuthController) RegisterGeetest() {
return
}
// RegisterGeetest 极验初校验
func (c *AuthController) ValidateGeetest() {
type Parameter struct {
GeetestChallenge string `form:"geetest_challenge"`
... ...
... ... @@ -26,6 +26,12 @@ type RequestLogin struct {
Password string `json:"password"`
}
//RequestLoginSms 短信验证登录请求
type RequestLoginSms struct {
Account string `json:"account"`
Code string `json:"code"`
}
//ResponseLogin 登录响应
type ResponseLogin struct {
Access LoginAuthToken `json:"access"`
... ...
... ... @@ -97,6 +97,8 @@ func init() {
beego.NSRouter("/login", &controllers.AuthController{}, "post:Login"),
beego.NSRouter("/startCaptcha", &controllers.AuthController{}, "post:RegisterGeetest"),
beego.NSRouter("/verifyCaptcha", &controllers.AuthController{}, "post:ValidateGeetest"),
beego.NSRouter("/login_sms", &controllers.AuthController{}, "post:LoginSms"),
beego.NSRouter("/sms_code", &controllers.AuthController{}, "post:SmsCode"),
)
nsUcenter := beego.NewNamespace("/ucenter",
beego.NSBefore(middleware.LogRequestData),
... ...