二维码模式更换

This commit is contained in:
QM303176530
2020-06-20 16:38:33 +08:00
parent f54c6f2124
commit 27e5c1786c
6 changed files with 22 additions and 80 deletions

View File

@@ -1,14 +1,15 @@
package v1
import (
"gin-vue-admin/global"
"fmt"
"gin-vue-admin/global/response"
resp "gin-vue-admin/model/response"
"gin-vue-admin/utils"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
)
var store = base64Captcha.DefaultMemStore
// @Tags base
// @Summary 生成验证码
// @Security ApiKeyAuth
@@ -17,20 +18,17 @@ import (
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha [post]
func Captcha(c *gin.Context) {
captchaId := captcha.NewLen(global.GVA_CONFIG.Captcha.KeyLong)
response.OkDetailed(resp.SysCaptchaResponse{
CaptchaId: captchaId,
PicPath: "/base/captcha/" + captchaId + ".png",
}, "验证码获取成功", c)
}
// @Tags base
// @Summary 生成验证码图片路径
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha/:captchaId [get]
func CaptchaImg(c *gin.Context) {
utils.GinCaptchaServeHTTP(c.Writer, c.Request)
//字符,公式,验证码配置
// 生成默认数字的driver
driver := base64Captcha.NewDriverDigit(80, 240, 5, 0.7, 80)
cp := base64Captcha.NewCaptcha(driver, store)
id, b64s, err := cp.Generate()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
} else {
response.OkDetailed(resp.SysCaptchaResponse{
CaptchaId: id,
PicPath: b64s,
}, "验证码获取成功", c)
}
}

View File

@@ -10,7 +10,6 @@ import (
resp "gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/dchest/captcha"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis"
@@ -67,7 +66,7 @@ func Login(c *gin.Context) {
response.FailWithMessage(UserVerifyErr.Error(), c)
return
}
if captcha.VerifyString(L.CaptchaId, L.Captcha) {
if store.Verify(L.CaptchaId, L.Captcha, true) {
U := &model.SysUser{Username: L.Username, Password: L.Password}
if err, user := service.Login(U); err != nil {
response.FailWithMessage(fmt.Sprintf("用户名密码错误或%v", err), c)