Skip to content

Commit 2160b28

Browse files
author
QM303176530
committed
二维码模式更换
1 parent 6ff5cfe commit 2160b28

File tree

6 files changed

+22
-80
lines changed

6 files changed

+22
-80
lines changed

server/api/v1/sys_captcha.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package v1
22

33
import (
4-
"gin-vue-admin/global"
4+
"fmt"
55
"gin-vue-admin/global/response"
66
resp "gin-vue-admin/model/response"
7-
"gin-vue-admin/utils"
8-
"github.com/dchest/captcha"
97
"github.com/gin-gonic/gin"
8+
"github.com/mojocn/base64Captcha"
109
)
1110

11+
var store = base64Captcha.DefaultMemStore
12+
1213
// @Tags base
1314
// @Summary 生成验证码
1415
// @Security ApiKeyAuth
@@ -17,20 +18,17 @@ import (
1718
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
1819
// @Router /base/captcha [post]
1920
func Captcha(c *gin.Context) {
20-
captchaId := captcha.NewLen(global.GVA_CONFIG.Captcha.KeyLong)
21-
response.OkDetailed(resp.SysCaptchaResponse{
22-
CaptchaId: captchaId,
23-
PicPath: "/base/captcha/" + captchaId + ".png",
24-
}, "验证码获取成功", c)
25-
}
26-
27-
// @Tags base
28-
// @Summary 生成验证码图片路径
29-
// @Security ApiKeyAuth
30-
// @accept application/json
31-
// @Produce application/json
32-
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
33-
// @Router /base/captcha/:captchaId [get]
34-
func CaptchaImg(c *gin.Context) {
35-
utils.GinCaptchaServeHTTP(c.Writer, c.Request)
21+
//字符,公式,验证码配置
22+
// 生成默认数字的driver
23+
driver := base64Captcha.NewDriverDigit(80, 240, 5, 0.7, 80)
24+
cp := base64Captcha.NewCaptcha(driver, store)
25+
id, b64s, err := cp.Generate()
26+
if err != nil {
27+
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
28+
} else {
29+
response.OkDetailed(resp.SysCaptchaResponse{
30+
CaptchaId: id,
31+
PicPath: b64s,
32+
}, "验证码获取成功", c)
33+
}
3634
}

server/api/v1/sys_user.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
resp "gin-vue-admin/model/response"
1111
"gin-vue-admin/service"
1212
"gin-vue-admin/utils"
13-
"github.com/dchest/captcha"
1413
"github.com/dgrijalva/jwt-go"
1514
"github.com/gin-gonic/gin"
1615
"github.com/go-redis/redis"
@@ -67,7 +66,7 @@ func Login(c *gin.Context) {
6766
response.FailWithMessage(UserVerifyErr.Error(), c)
6867
return
6968
}
70-
if captcha.VerifyString(L.CaptchaId, L.Captcha) {
69+
if store.Verify(L.CaptchaId, L.Captcha, true) {
7170
U := &model.SysUser{Username: L.Username, Password: L.Password}
7271
if err, user := service.Login(U); err != nil {
7372
response.FailWithMessage(fmt.Sprintf("用户名密码错误或%v", err), c)

server/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require (
2626
github.com/lib/pq v1.3.0 // indirect
2727
github.com/mailru/easyjson v0.7.1 // indirect
2828
github.com/mitchellh/mapstructure v1.2.2 // indirect
29+
github.com/mojocn/base64Captcha v1.3.1
2930
github.com/onsi/ginkgo v1.7.0 // indirect
3031
github.com/onsi/gomega v1.4.3 // indirect
3132
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7

server/router/sys_base.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ func InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
1111
BaseRouter.POST("register", v1.Register)
1212
BaseRouter.POST("login", v1.Login)
1313
BaseRouter.POST("captcha", v1.Captcha)
14-
BaseRouter.GET("captcha/:captchaId", v1.CaptchaImg)
1514
}
1615
return BaseRouter
1716
}

server/utils/captcha.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

web/src/view/login/login.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
<div class="vPic">
5353
<img
5454
v-if="picPath"
55-
:src="path + picPath"
55+
:src="picPath"
56+
width="100%"
57+
height="100%"
5658
alt="请输入验证码"
5759
@click="loginVefify()"
5860
/>
@@ -92,7 +94,6 @@
9294
<script>
9395
import { mapActions } from "vuex";
9496
import { captcha } from "@/api/user";
95-
const path = process.env.VUE_APP_BASE_API;
9697
export default {
9798
name: "Login",
9899
data() {
@@ -123,7 +124,6 @@ export default {
123124
username: [{ validator: checkUsername, trigger: "blur" }],
124125
password: [{ validator: checkPassword, trigger: "blur" }],
125126
},
126-
path: path,
127127
logVerify: "",
128128
picPath: "",
129129
};

0 commit comments

Comments
 (0)