feat(P1): Account 模型扩展 + 头像上传 + 个人简介 + Refresh Token 机制
This commit is contained in:
@@ -39,7 +39,7 @@ func GenerateToken(accountID uint, username string) (string, error) {
|
||||
AccountID: accountID,
|
||||
Username: username,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(24 * time.Hour)),
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(15 * time.Minute)),
|
||||
IssuedAt: jwt.NewNumericDate(now),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
},
|
||||
@@ -50,6 +50,14 @@ func GenerateToken(accountID uint, username string) (string, error) {
|
||||
return token.SignedString(jwtSecret())
|
||||
}
|
||||
|
||||
func GenerateRefreshToken(accountID uint) (string, error) {
|
||||
b := make([]byte, 32)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(b), nil
|
||||
}
|
||||
|
||||
func ParseToken(tokenString string) (*Claims, error) {
|
||||
token, err := jwt.ParseWithClaims(
|
||||
tokenString,
|
||||
|
||||
Reference in New Issue
Block a user