登录时设置手机号和openid为必填2
This commit is contained in:
parent
d68fab94cd
commit
94d25b4ec4
@ -32,6 +32,33 @@ func (r *Login) Login(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.OpenId == "" && req.Mobile == "" {
|
||||||
|
responses.FailWithMessage("登陆失败", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测参数
|
||||||
|
if req.Mobile != "" {
|
||||||
|
if req.Code == "" {
|
||||||
|
responses.FailWithMessage("请输入手机号验证码", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测验证码
|
||||||
|
if config.C.Env != "dev" {
|
||||||
|
code, _ := global.Redis.Get(c, "login_code_count_"+req.Mobile).Result()
|
||||||
|
if code == "" {
|
||||||
|
responses.FailWithMessage("验证码失效", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Code != code {
|
||||||
|
responses.FailWithMessage("验证码错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 开始事务
|
// 开始事务
|
||||||
tx := global.Db.Begin()
|
tx := global.Db.Begin()
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -63,22 +90,6 @@ func (r *Login) Login(c *gin.Context) {
|
|||||||
user, _ := userDao.GetUser(maps)
|
user, _ := userDao.GetUser(maps)
|
||||||
// 新用户处理方式
|
// 新用户处理方式
|
||||||
if user == nil {
|
if user == nil {
|
||||||
// 检测验证码
|
|
||||||
if req.Source == 1 {
|
|
||||||
if config.C.Env != "dev" {
|
|
||||||
code, _ := global.Redis.Get(c, "login_code_count_"+req.Mobile).Result()
|
|
||||||
if code == "" {
|
|
||||||
responses.FailWithMessage("验证码失效", c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Code != code {
|
|
||||||
responses.FailWithMessage("验证码错误", c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 登录ip
|
// 登录ip
|
||||||
publicService := service.PublicService{}
|
publicService := service.PublicService{}
|
||||||
loginIp := publicService.GetUserIP(c.Request)
|
loginIp := publicService.GetUserIP(c.Request)
|
||||||
|
|||||||
@ -6,10 +6,10 @@ type LoginRequest struct {
|
|||||||
|
|
||||||
// Login 登录
|
// Login 登录
|
||||||
type Login struct {
|
type Login struct {
|
||||||
Mobile string `json:"mobile" form:"mobile" label:"手机号" validate:"required"`
|
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
|
||||||
Code string `json:"code" form:"code" label:"验证码"`
|
Code string `json:"code" form:"code" label:"验证码"`
|
||||||
Source int `json:"source" form:"source" label:"来源" validate:"required"` // (1:app 2:公众号)
|
Source int `json:"source" form:"source" label:"来源" validate:"required"` // (1:app 2:公众号)
|
||||||
OpenId string `json:"openid" form:"openid" label:"openid" validate:"required"`
|
OpenId string `json:"openid" form:"openid" label:"openid"`
|
||||||
Nickname string `json:"nickname" form:"nickname" label:"用户昵称"`
|
Nickname string `json:"nickname" form:"nickname" label:"用户昵称"`
|
||||||
HeadImgUrl string `json:"headimgurl" form:"headimgurl" label:"头像"`
|
HeadImgUrl string `json:"headimgurl" form:"headimgurl" label:"头像"`
|
||||||
UnionId string `json:"unionid" form:"unionid" label:"unionid"`
|
UnionId string `json:"unionid" form:"unionid" label:"unionid"`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user