feat(P1): Account 模型扩展 + 头像上传 + 个人简介 + Refresh Token 机制

This commit is contained in:
Sisyphus
2026-04-25 18:49:16 +08:00
parent 2e0c5dd632
commit 9b20df4bf3
6 changed files with 392 additions and 146 deletions

View File

@@ -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,