From bc133393557841e147f7106a94f35ca56e97e022 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 19 Aug 2024 17:32:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E7=99=BB=E5=BD=951?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/Login.go | 33 +++++++++++++++++++++++---------- api/requests/Login.go | 4 ++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/api/controller/Login.go b/api/controller/Login.go index 4a47fcf..cd309eb 100644 --- a/api/controller/Login.go +++ b/api/controller/Login.go @@ -32,6 +32,11 @@ func (r *Login) Login(c *gin.Context) { return } + if req.OpenId == "" && req.Mobile == "" { + responses.FailWithMessage("登陆失败", c) + return + } + // 开始事务 tx := global.Db.Begin() defer func() { @@ -47,21 +52,29 @@ func (r *Login) Login(c *gin.Context) { // 检测用户信息 userDao := dao.UserDao{} maps := make(map[string]interface{}) - maps["mobile"] = req.Mobile + if req.OpenId != "" { + maps["open_id"] = req.OpenId + } + + if req.Mobile != "" { + maps["mobile"] = req.Mobile + } user, _ := userDao.GetUser(maps) // 新用户处理方式 if user == nil { // 检测验证码 - if config.C.Env != "dev" { - code, _ := global.Redis.Get(c, "login_code_count_"+req.Mobile).Result() - if code == "" { - responses.FailWithMessage("验证码失效", c) - return - } + if req.Mobile != "" { + 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 + if req.Code != code { + responses.FailWithMessage("验证码错误", c) + return + } } } diff --git a/api/requests/Login.go b/api/requests/Login.go index abf2ac3..7ebeae0 100644 --- a/api/requests/Login.go +++ b/api/requests/Login.go @@ -6,10 +6,10 @@ type LoginRequest struct { // Login 登录 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:"验证码"` 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:"用户昵称"` HeadImgUrl string `json:"headimgurl" form:"headimgurl" label:"头像"` UnionId string `json:"unionid" form:"unionid" label:"unionid"`