Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5819a8e08f | ||
|
|
a2e3bfab77 | ||
|
|
f1310d093e | ||
|
|
fd967b8c1d | ||
|
|
8d8ec866cd | ||
|
|
d8e54f4909 |
@@ -21,13 +21,13 @@ var (
|
||||
JwtSecretLen int
|
||||
)
|
||||
|
||||
func New(token string) {
|
||||
JwtSecret = []byte(token)
|
||||
func New(secret string) {
|
||||
JwtSecret = []byte(secret)
|
||||
JwtSecretLen = len(env.Runtime.JwtSecretKey)
|
||||
}
|
||||
|
||||
func GenerateTokenAes(id uint, identity, client, role string, owner any, extend map[string]string) (string, error) {
|
||||
if (JwtSecretLen == 16 || JwtSecretLen == 24 || JwtSecretLen == 32) == false {
|
||||
if !(JwtSecretLen == 16 || JwtSecretLen == 24 || JwtSecretLen == 32) {
|
||||
return "", errcode.ErrJWTSecretKey
|
||||
}
|
||||
expireTime := time.Now().Add(vars.JwtExpireDay)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var Response *Reply
|
||||
var Response Reply
|
||||
|
||||
type Reply struct {
|
||||
Code int `json:"code"`
|
||||
@@ -15,12 +15,11 @@ type Reply struct {
|
||||
|
||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||
reply.Code = 200
|
||||
reply.Data = data
|
||||
if data == nil {
|
||||
reply.Data = ""
|
||||
}
|
||||
|
||||
ctx.JSON(200, reply)
|
||||
return
|
||||
}
|
||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||
reply.Code = 500
|
||||
@@ -34,5 +33,4 @@ func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||
|
||||
// Send error
|
||||
ctx.JSON(200, reply)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -13,4 +13,5 @@ type JwtClaims struct {
|
||||
Owner any `json:"owner"`
|
||||
Role string `json:"role"`
|
||||
ExpiresAt int64 `json:"exp"`
|
||||
SsoToken string `json:"sso_token"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user