feature:提取创建claims和token的方法,方便后续插件扩展。

This commit is contained in:
pixelmaxQM
2024-07-27 00:16:48 +08:00
parent b10c7297fd
commit 62b84d454a
3 changed files with 54 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package utils
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
"github.com/gin-gonic/gin"
"github.com/gofrs/uuid/v5"
@@ -123,3 +124,19 @@ func GetUserName(c *gin.Context) string {
return waitUse.Username
}
}
func LoginToken(user system.Login) (token string, claims systemReq.CustomClaims, err error) {
j := &JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
claims = j.CreateClaims(systemReq.BaseClaims{
UUID: user.GetUUID(),
ID: user.GetUserId(),
NickName: user.GetNickname(),
Username: user.GetUsername(),
AuthorityId: user.GetAuthorityId(),
})
token, err = j.CreateToken(claims)
if err != nil {
return
}
return
}