浏览代码

新增验证码

rdluck 4 年之前
父节点
当前提交
79dbae5d96
共有 3 个文件被更改,包括 40 次插入4 次删除
  1. 37 2
      controllers/user.go
  2. 2 1
      models/user.go
  3. 1 1
      services/task.go

+ 37 - 2
controllers/user.go

@@ -50,14 +50,33 @@ func (this *UserController) Login() {
 		return
 	}
 	newUserId := 0
-	if req.LoginType == 1 {
-		if req.Mobile=="" {
+	if req.LoginType == 1 || req.LoginType == 3 {
+		if req.Mobile == "" {
 			br.Msg = "参数错误"
 			br.ErrMsg = "参数错误,手机号为空 为空"
 			return
 		}
+		if req.LoginType == 3 {
+			item, err := models.GetMsgCode(req.Mobile, req.VCode)
+			if err != nil {
+				if err.Error() == utils.ErrNoRow() {
+					br.Msg = "验证码错误,请重新输入"
+					br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+					return
+				} else {
+					br.Msg = "验证码错误,请重新输入"
+					br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+					return
+				}
+			}
+			if item == nil {
+				br.Msg = "验证码错误,请重新输入"
+				return
+			}
+		}
 		//BindMobile(openId, mobile string, userId, loginType int) (err error) {
 		req.Mobile = strings.Trim(req.Mobile, " ")
+		req.LoginType = 1
 		newUserId, err = models.PcBindMobile(unionId, req.Mobile, userId, req.LoginType)
 	} else if req.LoginType == 2 {
 		if req.Email == "" {
@@ -70,6 +89,22 @@ func (this *UserController) Login() {
 			br.Msg = "邮箱格式错误,请重新输入"
 			return
 		}
+		item, err := models.GetMsgCode(req.Mobile, req.VCode)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			} else {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			}
+		}
+		if item == nil {
+			br.Msg = "验证码错误,请重新输入"
+			return
+		}
 		newUserId, err = models.PcBindMobile(unionId, req.Email, userId, req.LoginType)
 	} else {
 		br.Msg = "无效的登录方式"

+ 2 - 1
models/user.go

@@ -33,9 +33,10 @@ type UserPermission struct {
 }
 
 type LoginReq struct {
-	LoginType int    `description:"登录方式:1:手机,2:邮箱"`
+	LoginType int    `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
 	Mobile    string `description:"手机号"`
 	Email     string `description:"邮箱"`
+	VCode     string `description:"验证码"`
 }
 
 func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {

+ 1 - 1
services/task.go

@@ -14,6 +14,6 @@ func Task() {
 	//解析报告
 	//GetArticleExpert()
 	//SearchByKeyWordQuery("")
-	
+
 	fmt.Println("end")
 }