Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nizhengjia888
gin-vue-admin
提交
c3f921d3
G
gin-vue-admin
项目概览
nizhengjia888
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c3f921d3
编写于
9月 01, 2021
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提升性能 修复前端tab页面bug 增加ws插件
上级
3ec0a7cf
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
97 addition
and
101 deletion
+97
-101
server/api/v1/system/sys_user.go
server/api/v1/system/sys_user.go
+2
-3
server/go.mod
server/go.mod
+2
-0
server/middleware/jwt.go
server/middleware/jwt.go
+9
-91
server/utils/jwt.go
server/utils/jwt.go
+71
-0
web/package.json
web/package.json
+1
-1
web/src/view/layout/aside/historyComponent/history.vue
web/src/view/layout/aside/historyComponent/history.vue
+11
-6
web/src/view/layout/index.vue
web/src/view/layout/index.vue
+1
-0
未找到文件。
server/api/v1/system/sys_user.go
浏览文件 @
c3f921d3
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"time"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
...
@@ -47,7 +46,7 @@ func (b *BaseApi) Login(c *gin.Context) {
...
@@ -47,7 +46,7 @@ func (b *BaseApi) Login(c *gin.Context) {
// 登录以后签发jwt
// 登录以后签发jwt
func
(
b
*
BaseApi
)
tokenNext
(
c
*
gin
.
Context
,
user
system
.
SysUser
)
{
func
(
b
*
BaseApi
)
tokenNext
(
c
*
gin
.
Context
,
user
system
.
SysUser
)
{
j
:=
&
middleware
.
JWT
{
SigningKey
:
[]
byte
(
global
.
GVA_CONFIG
.
JWT
.
SigningKey
)}
// 唯一签名
j
:=
&
utils
.
JWT
{
SigningKey
:
[]
byte
(
global
.
GVA_CONFIG
.
JWT
.
SigningKey
)}
// 唯一签名
claims
:=
systemReq
.
CustomClaims
{
claims
:=
systemReq
.
CustomClaims
{
UUID
:
user
.
UUID
,
UUID
:
user
.
UUID
,
ID
:
user
.
ID
,
ID
:
user
.
ID
,
...
@@ -210,7 +209,7 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
...
@@ -210,7 +209,7 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
response
.
FailWithMessage
(
err
.
Error
(),
c
)
response
.
FailWithMessage
(
err
.
Error
(),
c
)
}
else
{
}
else
{
claims
:=
utils
.
GetUserInfo
(
c
)
claims
:=
utils
.
GetUserInfo
(
c
)
j
:=
&
middleware
.
JWT
{
SigningKey
:
[]
byte
(
global
.
GVA_CONFIG
.
JWT
.
SigningKey
)}
// 唯一签名
j
:=
&
utils
.
JWT
{
SigningKey
:
[]
byte
(
global
.
GVA_CONFIG
.
JWT
.
SigningKey
)}
// 唯一签名
claims
.
AuthorityId
=
sua
.
AuthorityId
claims
.
AuthorityId
=
sua
.
AuthorityId
if
token
,
err
:=
j
.
CreateToken
(
*
claims
);
err
!=
nil
{
if
token
,
err
:=
j
.
CreateToken
(
*
claims
);
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"修改失败!"
,
zap
.
Any
(
"err"
,
err
))
global
.
GVA_LOG
.
Error
(
"修改失败!"
,
zap
.
Any
(
"err"
,
err
))
...
...
server/go.mod
浏览文件 @
c3f921d3
...
@@ -9,6 +9,7 @@ require (
...
@@ -9,6 +9,7 @@ require (
github.com/casbin/gorm-adapter/v3 v3.0.2
github.com/casbin/gorm-adapter/v3 v3.0.2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/flipped-aurora/gva-plugins v0.0.0-20210828060501-fc8b729b9a4a
github.com/flipped-aurora/gva-plugins v0.0.0-20210828060501-fc8b729b9a4a
github.com/flipped-aurora/ws v1.0.2
github.com/fsnotify/fsnotify v1.4.9
github.com/fsnotify/fsnotify v1.4.9
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
github.com/gin-gonic/gin v1.6.3
github.com/gin-gonic/gin v1.6.3
...
@@ -22,6 +23,7 @@ require (
...
@@ -22,6 +23,7 @@ require (
github.com/robfig/cron/v3 v3.0.1
github.com/robfig/cron/v3 v3.0.1
github.com/satori/go.uuid v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v3.21.1+incompatible
github.com/shirou/gopsutil v3.21.1+incompatible
github.com/songzhibin97/gkit v1.1.1
github.com/spf13/viper v1.7.0
github.com/spf13/viper v1.7.0
github.com/swaggo/gin-swagger v1.3.0
github.com/swaggo/gin-swagger v1.3.0
github.com/swaggo/swag v1.7.0
github.com/swaggo/swag v1.7.0
...
...
server/middleware/jwt.go
浏览文件 @
c3f921d3
package
middleware
package
middleware
import
(
import
(
"
error
s"
"
github.com/flipped-aurora/gin-vue-admin/server/util
s"
"strconv"
"strconv"
"time"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
"github.com/flipped-aurora/gin-vue-admin/server/service"
"github.com/flipped-aurora/gin-vue-admin/server/service"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"go.uber.org/zap"
)
)
...
@@ -32,11 +30,11 @@ func JWTAuth() gin.HandlerFunc {
...
@@ -32,11 +30,11 @@ func JWTAuth() gin.HandlerFunc {
c
.
Abort
()
c
.
Abort
()
return
return
}
}
j
:=
NewJWT
()
j
:=
utils
.
NewJWT
()
// parseToken 解析token包含的信息
// parseToken 解析token包含的信息
claims
,
err
:=
j
.
ParseToken
(
token
)
claims
,
err
:=
j
.
ParseToken
(
token
)
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
TokenExpired
{
if
err
==
utils
.
TokenExpired
{
response
.
FailWithDetailed
(
gin
.
H
{
"reload"
:
true
},
"授权已过期"
,
c
)
response
.
FailWithDetailed
(
gin
.
H
{
"reload"
:
true
},
"授权已过期"
,
c
)
c
.
Abort
()
c
.
Abort
()
return
return
...
@@ -45,11 +43,12 @@ func JWTAuth() gin.HandlerFunc {
...
@@ -45,11 +43,12 @@ func JWTAuth() gin.HandlerFunc {
c
.
Abort
()
c
.
Abort
()
return
return
}
}
if
err
,
_
=
userService
.
FindUserByUuid
(
claims
.
UUID
.
String
());
err
!=
nil
{
// 用户被删除的逻辑 需要优化 此处比较消耗性能 如果需要 请自行打开
_
=
jwtService
.
JsonInBlacklist
(
system
.
JwtBlacklist
{
Jwt
:
token
})
//if err, _ = userService.FindUserByUuid(claims.UUID.String()); err != nil {
response
.
FailWithDetailed
(
gin
.
H
{
"reload"
:
true
},
err
.
Error
(),
c
)
// _ = jwtService.JsonInBlacklist(system.JwtBlacklist{Jwt: token})
c
.
Abort
()
// response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c)
}
// c.Abort()
//}
if
claims
.
ExpiresAt
-
time
.
Now
()
.
Unix
()
<
claims
.
BufferTime
{
if
claims
.
ExpiresAt
-
time
.
Now
()
.
Unix
()
<
claims
.
BufferTime
{
claims
.
ExpiresAt
=
time
.
Now
()
.
Unix
()
+
global
.
GVA_CONFIG
.
JWT
.
ExpiresTime
claims
.
ExpiresAt
=
time
.
Now
()
.
Unix
()
+
global
.
GVA_CONFIG
.
JWT
.
ExpiresTime
newToken
,
_
:=
j
.
CreateTokenByOldToken
(
token
,
*
claims
)
newToken
,
_
:=
j
.
CreateTokenByOldToken
(
token
,
*
claims
)
...
@@ -72,84 +71,3 @@ func JWTAuth() gin.HandlerFunc {
...
@@ -72,84 +71,3 @@ func JWTAuth() gin.HandlerFunc {
}
}
}
}
type
JWT
struct
{
SigningKey
[]
byte
}
var
(
TokenExpired
=
errors
.
New
(
"Token is expired"
)
TokenNotValidYet
=
errors
.
New
(
"Token not active yet"
)
TokenMalformed
=
errors
.
New
(
"That's not even a token"
)
TokenInvalid
=
errors
.
New
(
"Couldn't handle this token:"
)
)
func
NewJWT
()
*
JWT
{
return
&
JWT
{
[]
byte
(
global
.
GVA_CONFIG
.
JWT
.
SigningKey
),
}
}
// 创建一个token
func
(
j
*
JWT
)
CreateToken
(
claims
request
.
CustomClaims
)
(
string
,
error
)
{
token
:=
jwt
.
NewWithClaims
(
jwt
.
SigningMethodHS256
,
claims
)
return
token
.
SignedString
(
j
.
SigningKey
)
}
// CreateTokenByOldToken 旧token 换新token 使用归并回源避免并发问题
func
(
j
*
JWT
)
CreateTokenByOldToken
(
oldToken
string
,
claims
request
.
CustomClaims
)
(
string
,
error
)
{
v
,
err
,
_
:=
global
.
GVA_Concurrency_Control
.
Do
(
"JWT:"
+
oldToken
,
func
()
(
interface
{},
error
)
{
return
j
.
CreateToken
(
claims
)
})
return
v
.
(
string
),
err
}
// 解析 token
func
(
j
*
JWT
)
ParseToken
(
tokenString
string
)
(
*
request
.
CustomClaims
,
error
)
{
token
,
err
:=
jwt
.
ParseWithClaims
(
tokenString
,
&
request
.
CustomClaims
{},
func
(
token
*
jwt
.
Token
)
(
i
interface
{},
e
error
)
{
return
j
.
SigningKey
,
nil
})
if
err
!=
nil
{
if
ve
,
ok
:=
err
.
(
*
jwt
.
ValidationError
);
ok
{
if
ve
.
Errors
&
jwt
.
ValidationErrorMalformed
!=
0
{
return
nil
,
TokenMalformed
}
else
if
ve
.
Errors
&
jwt
.
ValidationErrorExpired
!=
0
{
// Token is expired
return
nil
,
TokenExpired
}
else
if
ve
.
Errors
&
jwt
.
ValidationErrorNotValidYet
!=
0
{
return
nil
,
TokenNotValidYet
}
else
{
return
nil
,
TokenInvalid
}
}
}
if
token
!=
nil
{
if
claims
,
ok
:=
token
.
Claims
.
(
*
request
.
CustomClaims
);
ok
&&
token
.
Valid
{
return
claims
,
nil
}
return
nil
,
TokenInvalid
}
else
{
return
nil
,
TokenInvalid
}
}
// 更新token
//func (j *JWT) RefreshToken(tokenString string) (string, error) {
// jwt.TimeFunc = func() time.Time {
// return time.Unix(0, 0)
// }
// token, err := jwt.ParseWithClaims(tokenString, &request.CustomClaims{}, func(token *jwt.Token) (interface{}, error) {
// return j.SigningKey, nil
// })
// if err != nil {
// return "", err
// }
// if claims, ok := token.Claims.(*request.CustomClaims); ok && token.Valid {
// jwt.TimeFunc = time.Now
// claims.StandardClaims.ExpiresAt = time.Now().Unix() + 60*60*24*7
// return j.CreateToken(*claims)
// }
// return "", TokenInvalid
//}
server/utils/jwt.go
0 → 100644
浏览文件 @
c3f921d3
package
utils
import
(
"errors"
"github.com/dgrijalva/jwt-go"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
)
type
JWT
struct
{
SigningKey
[]
byte
}
var
(
TokenExpired
=
errors
.
New
(
"Token is expired"
)
TokenNotValidYet
=
errors
.
New
(
"Token not active yet"
)
TokenMalformed
=
errors
.
New
(
"That's not even a token"
)
TokenInvalid
=
errors
.
New
(
"Couldn't handle this token:"
)
)
func
NewJWT
()
*
JWT
{
return
&
JWT
{
[]
byte
(
global
.
GVA_CONFIG
.
JWT
.
SigningKey
),
}
}
// 创建一个token
func
(
j
*
JWT
)
CreateToken
(
claims
request
.
CustomClaims
)
(
string
,
error
)
{
token
:=
jwt
.
NewWithClaims
(
jwt
.
SigningMethodHS256
,
claims
)
return
token
.
SignedString
(
j
.
SigningKey
)
}
// CreateTokenByOldToken 旧token 换新token 使用归并回源避免并发问题
func
(
j
*
JWT
)
CreateTokenByOldToken
(
oldToken
string
,
claims
request
.
CustomClaims
)
(
string
,
error
)
{
v
,
err
,
_
:=
global
.
GVA_Concurrency_Control
.
Do
(
"JWT:"
+
oldToken
,
func
()
(
interface
{},
error
)
{
return
j
.
CreateToken
(
claims
)
})
return
v
.
(
string
),
err
}
// 解析 token
func
(
j
*
JWT
)
ParseToken
(
tokenString
string
)
(
*
request
.
CustomClaims
,
error
)
{
token
,
err
:=
jwt
.
ParseWithClaims
(
tokenString
,
&
request
.
CustomClaims
{},
func
(
token
*
jwt
.
Token
)
(
i
interface
{},
e
error
)
{
return
j
.
SigningKey
,
nil
})
if
err
!=
nil
{
if
ve
,
ok
:=
err
.
(
*
jwt
.
ValidationError
);
ok
{
if
ve
.
Errors
&
jwt
.
ValidationErrorMalformed
!=
0
{
return
nil
,
TokenMalformed
}
else
if
ve
.
Errors
&
jwt
.
ValidationErrorExpired
!=
0
{
// Token is expired
return
nil
,
TokenExpired
}
else
if
ve
.
Errors
&
jwt
.
ValidationErrorNotValidYet
!=
0
{
return
nil
,
TokenNotValidYet
}
else
{
return
nil
,
TokenInvalid
}
}
}
if
token
!=
nil
{
if
claims
,
ok
:=
token
.
Claims
.
(
*
request
.
CustomClaims
);
ok
&&
token
.
Valid
{
return
claims
,
nil
}
return
nil
,
TokenInvalid
}
else
{
return
nil
,
TokenInvalid
}
}
\ No newline at end of file
web/package.json
浏览文件 @
c3f921d3
{
{
"name"
:
"gin-vue-admin"
,
"name"
:
"gin-vue-admin"
,
"version"
:
"
0.1.0
"
,
"version"
:
"
2.3.5
"
,
"private"
:
true
,
"private"
:
true
,
"scripts"
:
{
"scripts"
:
{
"serve"
:
"node openDocument.js && vue-cli-service serve"
,
"serve"
:
"node openDocument.js && vue-cli-service serve"
,
...
...
web/src/view/layout/aside/historyComponent/history.vue
浏览文件 @
c3f921d3
...
@@ -74,6 +74,9 @@ export default {
...
@@ -74,6 +74,9 @@ export default {
}
}
},
},
$route
(
to
,
now
)
{
$route
(
to
,
now
)
{
if
(
to
.
name
===
'
Login
'
)
{
return
}
this
.
historys
=
this
.
historys
.
filter
(
item
=>
!
item
.
meta
.
closeTab
)
this
.
historys
=
this
.
historys
.
filter
(
item
=>
!
item
.
meta
.
closeTab
)
this
.
setTab
(
to
)
this
.
setTab
(
to
)
sessionStorage
.
setItem
(
'
historys
'
,
JSON
.
stringify
(
this
.
historys
))
sessionStorage
.
setItem
(
'
historys
'
,
JSON
.
stringify
(
this
.
historys
))
...
@@ -84,6 +87,14 @@ export default {
...
@@ -84,6 +87,14 @@ export default {
}
}
},
},
created
()
{
created
()
{
// 全局监听 关闭当前页面函数
emitter
.
on
(
'
closeThisPage
'
,
()
=>
{
this
.
removeTab
(
this
.
name
(
this
.
$route
))
})
// 全局监听 关闭所有页面函数
emitter
.
on
(
'
closeAllPage
'
,
()
=>
{
this
.
closeAll
()
})
emitter
.
on
(
'
mobile
'
,
isMobile
=>
{
emitter
.
on
(
'
mobile
'
,
isMobile
=>
{
this
.
isMobile
=
isMobile
this
.
isMobile
=
isMobile
})
})
...
@@ -109,12 +120,6 @@ export default {
...
@@ -109,12 +120,6 @@ export default {
}
}
this
.
setTab
(
this
.
$route
)
this
.
setTab
(
this
.
$route
)
},
},
mounted
()
{
// 全局监听 关闭当前页面函数
emitter
.
on
(
'
closeThisPage
'
,
()
=>
{
this
.
removeTab
(
this
.
name
(
this
.
$route
))
})
},
beforeDestroy
()
{
beforeDestroy
()
{
emitter
.
off
(
'
collapse
'
)
emitter
.
off
(
'
collapse
'
)
emitter
.
off
(
'
mobile
'
)
emitter
.
off
(
'
mobile
'
)
...
...
web/src/view/layout/index.vue
浏览文件 @
c3f921d3
...
@@ -212,6 +212,7 @@ export default {
...
@@ -212,6 +212,7 @@ export default {
authorityId
:
id
authorityId
:
id
})
})
if
(
res
.
code
===
0
)
{
if
(
res
.
code
===
0
)
{
emitter
.
emit
(
'
closeAllPage
'
)
window
.
location
.
reload
()
window
.
location
.
reload
()
}
}
},
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录