Skip to content

Commit 9ccb543

Browse files
author
pixel
committed
Merge branch 'gva_gormv2_dev' of https://github.com/flipped-aurora/gin-vue-admin
2 parents 928d816 + d428ed6 commit 9ccb543

File tree

9 files changed

+113
-88
lines changed

9 files changed

+113
-88
lines changed

server/api/v1/sys_user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func tokenNext(c *gin.Context, user model.SysUser) {
5050
NickName: user.NickName,
5151
Username: user.Username,
5252
AuthorityId: user.AuthorityId,
53-
BufferTime: 60 * 60 * 24, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
53+
BufferTime: global.GVA_CONFIG.JWT.BufferTime, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
5454
StandardClaims: jwt.StandardClaims{
55-
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
56-
ExpiresAt: time.Now().Unix() + 60*60*24*7, // 过期时间 7天
57-
Issuer: "qmPlus", // 签名的发行者
55+
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
56+
ExpiresAt: time.Now().Unix() + global.GVA_CONFIG.JWT.ExpiresTime, // 过期时间 7天 配置文件
57+
Issuer: "qmPlus", // 签名的发行者
5858
},
5959
}
6060
token, err := j.CreateToken(claims)

server/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# jwt configuration
44
jwt:
55
signing-key: 'qmPlus'
6+
expires-time: 604800
7+
buffer-time: 86400
68

79
# zap logger configuration
810
zap:

server/config/jwt.go

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

33
type JWT struct {
4-
SigningKey string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"`
4+
SigningKey string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"`
5+
ExpiresTime int64 `mapstructure:"expires-time" json:"expiresTime" yaml:"expires-time"`
6+
BufferTime int64 `mapstructure:"buffer-time" json:"bufferTime" yaml:"buffer-time"`
57
}

server/middleware/jwt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func JWTAuth() gin.HandlerFunc {
4747
c.Abort()
4848
}
4949
if claims.ExpiresAt-time.Now().Unix() < claims.BufferTime {
50-
claims.ExpiresAt = time.Now().Unix() + 60*60*24*7
50+
claims.ExpiresAt = time.Now().Unix() + global.GVA_CONFIG.JWT.ExpiresTime
5151
newToken, _ := j.CreateToken(*claims)
5252
newClaims, _ := j.ParseToken(newToken)
5353
c.Header("new-token", newToken)

server/service/jwt_black_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func GetRedisJWT(userName string) (err error, redisJWT string) {
4949

5050
func SetRedisJWT(jwt string, userName string) (err error) {
5151
// 此处过期时间等于jwt过期时间
52-
timer := 60 * 60 * 24 * 7 * time.Second
52+
timer := time.Duration(global.GVA_CONFIG.JWT.ExpiresTime) * time.Second
5353
err = global.GVA_REDIS.Set(userName, jwt, timer).Err()
5454
return err
5555
}

web/debug.log

Lines changed: 0 additions & 1 deletion
This file was deleted.

web/package-lock.json

Lines changed: 88 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/src/store/module/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const user = {
4646
} else {
4747
router.push({ path: '/layout/dashboard' })
4848
}
49+
return true
4950
}
5051
},
5152
async LoginOut({ commit }) {

web/src/view/login/login.vue

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@
2020
@keyup.enter.native="submitForm"
2121
>
2222
<el-form-item prop="username">
23-
<el-input
24-
placeholder="请输入用户名"
25-
v-model="loginForm.username"
26-
>
27-
<i
28-
class="el-input__icon el-icon-user"
29-
slot="suffix"
30-
></i></el-input>
23+
<el-input placeholder="请输入用户名" v-model="loginForm.username">
24+
<i class="el-input__icon el-icon-user" slot="suffix"></i
25+
></el-input>
3126
</el-form-item>
3227
<el-form-item prop="password">
3328
<el-input
@@ -42,12 +37,12 @@
4237
></i>
4338
</el-input>
4439
</el-form-item>
45-
<el-form-item style="position:relative">
40+
<el-form-item style="position: relative">
4641
<el-input
4742
v-model="loginForm.captcha"
4843
name="logVerify"
4944
placeholder="请输入验证码"
50-
style="width:60%"
45+
style="width: 60%"
5146
/>
5247
<div class="vPic">
5348
<img
@@ -61,7 +56,7 @@
6156
</div>
6257
</el-form-item>
6358
<el-form-item>
64-
<el-button type="primary" @click="submitForm" style="width:100%"
59+
<el-button type="primary" @click="submitForm" style="width: 100%"
6560
>登 录</el-button
6661
>
6762
</el-form-item>
@@ -83,9 +78,7 @@
8378
><img src="@/assets/video.png" class="link-icon"
8479
/></a>
8580
</div>
86-
<div class="copyright">
87-
Copyright &copy; {{ curYear }} 💖flipped-aurora
88-
</div>
81+
<div class="copyright">Copyright &copy; {{ curYear }} 💖flipped-aurora</div>
8982
</div>
9083
</div>
9184
</div>
@@ -135,13 +128,15 @@ export default {
135128
methods: {
136129
...mapActions("user", ["LoginIn"]),
137130
async login() {
138-
await this.LoginIn(this.loginForm);
131+
return await this.LoginIn(this.loginForm);
139132
},
140133
async submitForm() {
141134
this.$refs.loginForm.validate(async (v) => {
142135
if (v) {
143-
this.login();
144-
this.loginVefify();
136+
const flag = await this.login();
137+
if (!flag) {
138+
this.loginVefify();
139+
}
145140
} else {
146141
this.$message({
147142
type: "error",
@@ -167,6 +162,5 @@ export default {
167162
</script>
168163

169164
<style scoped lang="scss">
170-
@import '@/style/login.scss';
171-
165+
@import "@/style/login.scss";
172166
</style>

0 commit comments

Comments
 (0)