feat: user & article: dev complete

This commit is contained in:
fallen-angle
2022-02-27 16:36:33 +08:00
parent 4f3b16ab9d
commit 80ca1cd46e
33 changed files with 2373 additions and 185 deletions

View File

@@ -58,7 +58,7 @@ func RenewToken(tokenStr string) string {
}
fmt.Println(expireDuration)
claims["exp"] = time.Now().Add(15 * 24 * time.Hour).Unix()
claims["exp"] = time.Now().Add(global.TOKEN_EXPIRE_DAYS * 24 * time.Hour).Unix()
token = jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
tokenStr, err = token.SignedString(JWT_KEY)
if err != nil {
@@ -66,3 +66,18 @@ func RenewToken(tokenStr string) string {
}
return tokenStr
}
func ParseClaims(tokenStr string) jwt.MapClaims {
token, err := jwt.Parse(tokenStr, func(t *jwt.Token) (interface{}, error) {
return JWT_KEY, nil
})
if err != nil {
switch err.(*jwt.ValidationError).Errors {
case jwt.ValidationErrorSignatureInvalid:
return nil
case jwt.ValidationErrorIssuedAt:
return nil
}
}
return token.Claims.(jwt.MapClaims)
}