Skip to content

Commit 4e1e57d

Browse files
author
piexlmax
committed
Merge branch 'main' of github.com:flipped-aurora/gin-vue-admin
2 parents 9092d3b + 0ef9aac commit 4e1e57d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+675
-632
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SHELL = /bin/bash
22

33
#SCRIPT_DIR = $(shell pwd)/etc/script
44
#请选择golang版本
5-
BUILD_IMAGE_SERVER = golang:1.16
5+
BUILD_IMAGE_SERVER = golang:1.18
66
#请选择node版本
77
BUILD_IMAGE_WEB = node:16
88
#项目名称

deploy/docker-compose/docker-compose-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434
ipv4_address: 177.7.0.11
3535

3636
server:
37-
image: golang:1.16
37+
image: golang:1.18
3838
container_name: gva-server
3939
hostname: gva-server
4040
restart: always

deploy/kubernetes/server/gva-server-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ spec:
2929
- containerPort: 8888
3030
name: http
3131
volumeMounts:
32-
- mountPath: /go/src/github.com/flipped-aurora/gin-vue-admin/server/config.yaml
32+
- mountPath: /go/src/github.com/flipped-aurora/gin-vue-admin/server/config.docker.yaml
3333
name: config
3434
subPath: config.yaml
3535
- mountPath: /etc/localtime

server/api/v1/example/enter.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ package example
33
import "github.com/flipped-aurora/gin-vue-admin/server/service"
44

55
type ApiGroup struct {
6-
ExcelApi
76
CustomerApi
87
FileUploadAndDownloadApi
98
}
109

1110
var (
12-
excelService = service.ServiceGroupApp.ExampleServiceGroup.ExcelService
1311
customerService = service.ServiceGroupApp.ExampleServiceGroup.CustomerService
1412
fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService
1513
)

server/api/v1/example/exa_excel.go

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

server/api/v1/system/sys_captcha.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package system
22

33
import (
4+
"time"
5+
46
"github.com/flipped-aurora/gin-vue-admin/server/global"
57
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
68
systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
@@ -21,9 +23,22 @@ type BaseApi struct{}
2123
// @Security ApiKeyAuth
2224
// @accept application/json
2325
// @Produce application/json
24-
// @Success 200 {object} response.Response{data=systemRes.SysCaptchaResponse,msg=string} "生成验证码,返回包括随机数id,base64,验证码长度"
26+
// @Success 200 {object} response.Response{data=systemRes.SysCaptchaResponse,msg=string} "生成验证码,返回包括随机数id,base64,验证码长度,是否开启验证码"
2527
// @Router /base/captcha [post]
2628
func (b *BaseApi) Captcha(c *gin.Context) {
29+
// 判断验证码是否开启
30+
openCaptcha := global.GVA_CONFIG.Captcha.OpenCaptcha // 是否开启防爆次数
31+
openCaptchaTimeOut := global.GVA_CONFIG.Captcha.OpenCaptchaTimeOut // 缓存超时时间
32+
key := c.ClientIP()
33+
v, ok := global.BlackCache.Get(key)
34+
if !ok {
35+
global.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
36+
}
37+
38+
var oc bool
39+
if openCaptcha == 0 || openCaptcha < interfaceToInt(v) {
40+
oc = true
41+
}
2742
// 字符,公式,验证码配置
2843
// 生成默认数字的driver
2944
driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80)
@@ -39,5 +54,17 @@ func (b *BaseApi) Captcha(c *gin.Context) {
3954
CaptchaId: id,
4055
PicPath: b64s,
4156
CaptchaLength: global.GVA_CONFIG.Captcha.KeyLong,
57+
OpenCaptcha: oc,
4258
}, "验证码获取成功", c)
4359
}
60+
61+
// 类型转换
62+
func interfaceToInt(v interface{}) (i int) {
63+
switch v := v.(type) {
64+
case int:
65+
i = v
66+
default:
67+
i = 0
68+
}
69+
return
70+
}

server/api/v1/system/sys_user.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package system
22

33
import (
44
"strconv"
5+
"time"
56

67
"github.com/flipped-aurora/gin-vue-admin/server/global"
78
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
@@ -26,6 +27,8 @@ import (
2627
func (b *BaseApi) Login(c *gin.Context) {
2728
var l systemReq.Login
2829
err := c.ShouldBindJSON(&l)
30+
key := c.ClientIP()
31+
2932
if err != nil {
3033
response.FailWithMessage(err.Error(), c)
3134
return
@@ -35,22 +38,42 @@ func (b *BaseApi) Login(c *gin.Context) {
3538
response.FailWithMessage(err.Error(), c)
3639
return
3740
}
38-
if store.Verify(l.CaptchaId, l.Captcha, true) {
41+
42+
// 判断验证码是否开启
43+
openCaptcha := global.GVA_CONFIG.Captcha.OpenCaptcha // 是否开启防爆次数
44+
openCaptchaTimeOut := global.GVA_CONFIG.Captcha.OpenCaptchaTimeOut // 缓存超时时间
45+
v, ok := global.BlackCache.Get(key)
46+
if !ok {
47+
global.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
48+
}
49+
50+
var oc bool
51+
if openCaptcha == 0 || openCaptcha < interfaceToInt(v) {
52+
oc = true
53+
}
54+
55+
if !oc || store.Verify(l.CaptchaId, l.Captcha, true) {
3956
u := &system.SysUser{Username: l.Username, Password: l.Password}
4057
user, err := userService.Login(u)
4158
if err != nil {
4259
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Error(err))
60+
// 验证码次数+1
61+
global.BlackCache.Increment(key, 1)
4362
response.FailWithMessage("用户名不存在或者密码错误", c)
4463
return
4564
}
4665
if user.Enable != 1 {
4766
global.GVA_LOG.Error("登陆失败! 用户被禁止登录!")
67+
// 验证码次数+1
68+
global.BlackCache.Increment(key, 1)
4869
response.FailWithMessage("用户被禁止登录", c)
4970
return
5071
}
5172
b.TokenNext(c, *user)
5273
return
5374
}
75+
// 验证码次数+1
76+
global.BlackCache.Increment(key, 1)
5477
response.FailWithMessage("验证码错误", c)
5578
}
5679

server/config.docker.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ captcha:
5151
key-long: 6
5252
img-width: 240
5353
img-height: 80
54+
open-captcha: 0 # 0代表一直开启,大于0代表限制次数
55+
open-captcha-timeout: 3600 # open-captcha大于0时才生效
5456

5557
# mysql connect configuration
5658
# 未初始化之前请勿手动修改数据库信息!!!如果一定要手动初始化请看(https://gin-vue-admin.com/docs/first_master)

server/config.yaml

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ email:
3535

3636
# system configuration
3737
system:
38-
env: public # Change to "develop" to skip authentication for development mode
38+
env: public # Change to "develop" to skip authentication for development mode
3939
addr: 8888
4040
db-type: mysql
41-
oss-type: local # 控制oss选择走本地还是 七牛等其他仓 自行增加其他oss仓可以在 server/utils/upload/upload.go 中 NewOss函数配置
42-
use-redis: false # 使用redis
41+
oss-type: local # 控制oss选择走本地还是 七牛等其他仓 自行增加其他oss仓可以在 server/utils/upload/upload.go 中 NewOss函数配置
42+
use-redis: false # 使用redis
4343
use-multipoint: false
4444
# IP限制次数 一个小时15000次
4545
iplimit-count: 15000
@@ -51,6 +51,8 @@ captcha:
5151
key-long: 6
5252
img-width: 240
5353
img-height: 80
54+
open-captcha: 0 # 0代表一直开启,大于0代表限制次数
55+
open-captcha-timeout: 3600 # open-captcha大于0时才生效
5456

5557
# mysql connect configuration
5658
# 未初始化之前请勿手动修改数据库信息!!!如果一定要手动初始化请看(https://gin-vue-admin.com/docs/first_master)
@@ -79,10 +81,31 @@ pgsql:
7981
max-open-conns: 100
8082
log-mode: ""
8183
log-zap: false
82-
84+
oracle:
85+
path: ""
86+
port: ""
87+
config: ""
88+
db-name: ""
89+
username: ""
90+
password: ""
91+
max-idle-conns: 10
92+
max-open-conns: 100
93+
log-mode: ""
94+
log-zap: false
95+
mssql:
96+
path: ""
97+
port: ""
98+
config: ""
99+
db-name: ""
100+
username: ""
101+
password: ""
102+
max-idle-conns: 10
103+
max-open-conns: 100
104+
log-mode: ""
105+
log-zap: false
83106
db-list:
84107
- disable: true # 是否禁用
85-
type: "" # 数据库的类型,目前支持mysql、pgsql
108+
type: "" # 数据库的类型,目前支持mysql、pgsql、mssql、oracle
86109
alias-name: "" # 数据库的名称,注意: alias-name 需要在db-list中唯一
87110
path: ""
88111
port: ""
@@ -95,7 +118,6 @@ db-list:
95118
log-mode: ""
96119
log-zap: false
97120

98-
99121
# local configuration
100122
local:
101123
path: uploads/file
@@ -175,7 +197,7 @@ excel:
175197
# timer task db clear table
176198
Timer:
177199
start: true
178-
spec: "@daily" # 定时任务详细配置参考 https://pkg.go.dev/github.com/robfig/cron/v3
200+
spec: "@daily" # 定时任务详细配置参考 https://pkg.go.dev/github.com/robfig/cron/v3
179201
detail:
180202
- tableName: sys_operation_records
181203
compareField: created_at
@@ -187,15 +209,16 @@ Timer:
187209
# 跨域配置
188210
# 需要配合 server/initialize/router.go#L32 使用
189211
cors:
190-
mode: whitelist # 放行模式: allow-all, 放行全部; whitelist, 白名单模式, 来自白名单内域名的请求添加 cors 头; strict-whitelist 严格白名单模式, 白名单外的请求一律拒绝
212+
mode: strict-whitelist # 放行模式: allow-all, 放行全部; whitelist, 白名单模式, 来自白名单内域名的请求添加 cors 头; strict-whitelist 严格白名单模式, 白名单外的请求一律拒绝
191213
whitelist:
192214
- allow-origin: example1.com
193-
allow-headers: content-type
194-
allow-methods: GET, POST
215+
allow-headers: Content-Type,AccessToken,X-CSRF-Token, Authorization, Token,X-Token,X-User-Id
216+
allow-methods: POST, GET
195217
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
218+
196219
allow-credentials: true # 布尔值
197220
- allow-origin: example2.com
198221
allow-headers: content-type
199222
allow-methods: GET, POST
200223
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
201-
allow-credentials: true # 布尔值
224+
allow-credentials: true # 布尔值

server/config/captcha.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package config
22

33
type Captcha struct {
4-
KeyLong int `mapstructure:"key-long" json:"key-long" yaml:"key-long"` // 验证码长度
5-
ImgWidth int `mapstructure:"img-width" json:"img-width" yaml:"img-width"` // 验证码宽度
6-
ImgHeight int `mapstructure:"img-height" json:"img-height" yaml:"img-height"` // 验证码高度
4+
KeyLong int `mapstructure:"key-long" json:"key-long" yaml:"key-long"` // 验证码长度
5+
ImgWidth int `mapstructure:"img-width" json:"img-width" yaml:"img-width"` // 验证码宽度
6+
ImgHeight int `mapstructure:"img-height" json:"img-height" yaml:"img-height"` // 验证码高度
7+
OpenCaptcha int `mapstructure:"open-captcha" json:"open-captcha" yaml:"open-captcha"` // 防爆破验证码开启此数,0代表每次登录都需要验证码,其他数字代表错误密码此数,如3代表错误三次后出现验证码
8+
OpenCaptchaTimeOut int `mapstructure:"open-captcha-timeout" json:"open-captcha-timeout" yaml:"open-captcha-timeout"` // 防爆破验证码超时时间,单位:s(秒)
79
}

0 commit comments

Comments
 (0)