|
|
@ -10,7 +10,6 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
|
|
"github.com/rocboss/paopao-ce/internal/conf"
|
|
|
|
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/app"
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/app"
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/xerror"
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/xerror"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -41,7 +40,7 @@ func JWT() gin.HandlerFunc {
|
|
|
|
// 加载用户信息
|
|
|
|
// 加载用户信息
|
|
|
|
if user, err := ums.GetUserByID(claims.UID); err == nil {
|
|
|
|
if user, err := ums.GetUserByID(claims.UID); err == nil {
|
|
|
|
// 强制下线机制
|
|
|
|
// 强制下线机制
|
|
|
|
if (conf.JWTSetting.Issuer + ":" + user.Salt) == claims.Issuer {
|
|
|
|
if app.IssuerFrom(user.Salt) == claims.Issuer {
|
|
|
|
c.Set("USER", user)
|
|
|
|
c.Set("USER", user)
|
|
|
|
c.Set("UID", claims.UID)
|
|
|
|
c.Set("UID", claims.UID)
|
|
|
|
c.Set("USERNAME", claims.Username)
|
|
|
|
c.Set("USERNAME", claims.Username)
|
|
|
@ -133,7 +132,7 @@ func JwtLoose() gin.HandlerFunc {
|
|
|
|
if claims, err := app.ParseToken(token); err == nil {
|
|
|
|
if claims, err := app.ParseToken(token); err == nil {
|
|
|
|
// 加载用户信息
|
|
|
|
// 加载用户信息
|
|
|
|
user, err := ums.GetUserByID(claims.UID)
|
|
|
|
user, err := ums.GetUserByID(claims.UID)
|
|
|
|
if err == nil && (conf.JWTSetting.Issuer+":"+user.Salt) == claims.Issuer {
|
|
|
|
if err == nil && app.IssuerFrom(user.Salt) == claims.Issuer {
|
|
|
|
c.Set("UID", claims.UID)
|
|
|
|
c.Set("UID", claims.UID)
|
|
|
|
c.Set("USERNAME", claims.Username)
|
|
|
|
c.Set("USERNAME", claims.Username)
|
|
|
|
c.Set("USER", user)
|
|
|
|
c.Set("USER", user)
|
|
|
|