Browse Source

新增校验接口

rdluck 4 years ago
parent
commit
1f0e598bbf
2 changed files with 36 additions and 52 deletions
  1. 28 52
      controllers/user_pc.go
  2. 8 0
      models/wx_user.go

+ 28 - 52
controllers/user_pc.go

@@ -62,57 +62,6 @@ func (this *UserCommonController) GetGraphicVerifyCode() {
 	br.Success = true
 }
 
-
-// @Title 获取图形验证码
-// @Description 获取图形验证码
-// @Param	request	body models.CheckGraphicVerifyCodeReq true "type json string"
-// @Success ret=200 校验验证码成功
-// @router /pc/checkGraphicVerifyCode [post]
-func (this *UserCommonController) CheckGraphicVerifyCode() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-	var req models.CheckGraphicVerifyCodeReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-	if req.VerifyId == "" {
-		br.Msg = "参数错误!"
-		return
-	}
-	if req.VerifyCode == "" {
-		br.Msg="请输入验证码"
-		return
-	}
-	item,err:=models.GetGraphicVerifyById(req.VerifyId)
-	if err!=nil {
-		if err.Error()==utils.ErrNoRow() {
-			br.Msg = "验证码不存在,请刷新页面!"
-			return
-		}
-		br.Msg = "校验验证码失败!"
-		return
-	}
-	if item.VerifyCode!=req.VerifyCode {
-		br.Msg = "验证码错误,请重新输入!"
-		return
-	}
-	checkoutTime:=time.Now().Add(15*time.Minute)
-	if item.CreateTime.After(checkoutTime) {
-		br.Msg = "验证码过期,请重新输入!"
-		return
-	}
-	br.Ret = 200
-	br.Msg = "校验成功"
-	br.Success = true
-}
-
-
 // @Title 登录
 // @Description 登录接口
 // @Param	request	body models.LoginReq true "type json string"
@@ -124,7 +73,7 @@ func (this *UserCommonController) Login() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	var req models.LoginReq
+	var req models.PcLoginReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
 		br.Msg = "参数解析异常!"
@@ -135,6 +84,33 @@ func (this *UserCommonController) Login() {
 	userId:=0
 	var isAdd bool
 	if req.LoginType == 1 {
+		if req.VerifyId == "" {
+			br.Msg = "参数错误!"
+			return
+		}
+		if req.VerifyCode == "" {
+			br.Msg="请输入验证码"
+			return
+		}
+		item,err:=models.GetGraphicVerifyById(req.VerifyId)
+		if err!=nil {
+			if err.Error()==utils.ErrNoRow() {
+				br.Msg = "验证码不存在,请刷新页面!"
+				return
+			}
+			br.Msg = "校验验证码失败!"
+			return
+		}
+		if item.VerifyCode!=req.VerifyCode {
+			br.Msg = "验证码错误,请重新输入!"
+			return
+		}
+		checkoutTime:=time.Now().Add(15*time.Minute)
+		if item.CreateTime.After(checkoutTime) {
+			br.Msg = "验证码过期,请重新输入!"
+			return
+		}
+
 		//BindMobile(openId, mobile string, userId, loginType int) (err error) {
 		//newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
 	} else if req.LoginType == 2 {

+ 8 - 0
models/wx_user.go

@@ -237,4 +237,12 @@ func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
 	sql := `SELECT * FROM wx_user WHERE email=? `
 	err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
 	return
+}
+
+type PcLoginReq struct {
+	LoginType int    `description:"登录方式:1:手机,2:邮箱"`
+	Mobile    string `description:"手机号"`
+	Email     string `description:"邮箱"`
+	VerifyId   string
+	VerifyCode string
 }