|
|
@@ -7,8 +7,6 @@ import (
|
|
|
"strconv"
|
|
|
)
|
|
|
|
|
|
-const captcha_session = "image_captcha"
|
|
|
-
|
|
|
// _Image
|
|
|
// @Title _Image
|
|
|
// @Description 获取图片验证码
|
|
|
@@ -21,19 +19,16 @@ func Captcha_Image(c *entitys.CtrlContext) {
|
|
|
width, _ := strconv.Atoi(c.Ctx.Query("w"))
|
|
|
height, _ := strconv.Atoi(c.Ctx.Query("h"))
|
|
|
length, _ := strconv.Atoi(c.Ctx.Query("l"))
|
|
|
- captchaKey := captcha_session + c.Ctx.Query("code")
|
|
|
+
|
|
|
captchaId, image, err := utils.GenerateImageCaptcha(width, height, length)
|
|
|
|
|
|
if err == nil {
|
|
|
- utils.SetSession(c.Ctx, captchaKey, captchaId)
|
|
|
- c.Ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
- c.Ctx.Header("Pragma", "no-cache")
|
|
|
- c.Ctx.Header("Expires", "0")
|
|
|
- c.Ctx.Header("Content-Type", "image/png")
|
|
|
- c.Ctx.Writer.Write(image.Bytes())
|
|
|
- c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
|
|
|
+ result := map[string]interface{}{
|
|
|
+ "captcha_key": captchaId,
|
|
|
+ "captcha_image": image.Bytes(),
|
|
|
+ }
|
|
|
+ c.Ctx.JSON(200, sysmodel.SysReturn{200, "", result})
|
|
|
} else {
|
|
|
- utils.SetSession(c.Ctx, captchaKey, "")
|
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
|
|
|
}
|
|
|
}
|
|
|
@@ -65,7 +60,8 @@ func Captcha_Sms(c *entitys.CtrlContext) {
|
|
|
// @Description 校验验证码
|
|
|
// @Param type int false "验证类型 0:图片验证码 1:短信验证码"
|
|
|
// @Param captcha string false "验证码"
|
|
|
-// @Param mobile string false "手机号码 短信验证码时传"
|
|
|
+// @Param mobile string false "短信验证码的手机号码"
|
|
|
+// @Param key string false "图片验证码的key"
|
|
|
// @Success 200 {object} Account
|
|
|
// @Failure 403 :id is empty
|
|
|
func Captcha_Check(c *entitys.CtrlContext) {
|
|
|
@@ -80,19 +76,19 @@ func Captcha_Check(c *entitys.CtrlContext) {
|
|
|
|
|
|
switch check_type {
|
|
|
case "0":
|
|
|
- captchaKey := captcha_session + c.Ctx.Query("code")
|
|
|
- captchaId := utils.GetSession(c.Ctx, captchaKey, "").(string)
|
|
|
- check = utils.ImageCaptchaCheck(captcha, captchaId)
|
|
|
- if check {
|
|
|
- c.Ctx.Set(captchaKey, "")
|
|
|
+ captchaId := c.Ctx.Query("key")
|
|
|
+ if captchaId == "" {
|
|
|
+ c.Ctx.JSON(500, sysmodel.SysReturn{500, "验证码key不能为空", nil})
|
|
|
+ return
|
|
|
}
|
|
|
+ check = utils.ImageCaptchaCheck(captcha, captchaId)
|
|
|
case "1":
|
|
|
mobile := c.Ctx.Query("mobile")
|
|
|
if mobile == "" {
|
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, "手机号码不能为空", nil})
|
|
|
return
|
|
|
}
|
|
|
- check= utils.SmsCaptchaCheck(captcha, mobile)
|
|
|
+ check = utils.SmsCaptchaCheck(captcha, mobile)
|
|
|
default:
|
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, "验证类型错误", nil})
|
|
|
return
|
|
|
@@ -100,7 +96,7 @@ func Captcha_Check(c *entitys.CtrlContext) {
|
|
|
|
|
|
if check {
|
|
|
c.Ctx.JSON(200, sysmodel.SysReturn{200, "验证成功", nil})
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
c.Ctx.JSON(500, sysmodel.SysReturn{500, "验证失败", nil})
|
|
|
}
|
|
|
}
|