52 lines
1.0 KiB
Go
Raw Normal View History

2024-09-29 21:12:57 +08:00
package dto
2024-09-30 22:49:21 +08:00
import (
"github.com/golang-jwt/jwt/v5"
"time"
)
2024-09-29 21:12:57 +08:00
type UserVO struct {
2024-09-30 22:49:21 +08:00
Sn string `json:"sn"`
Token string `json:"token"`
Platform string `json:"platform"`
2024-09-29 21:12:57 +08:00
2024-09-30 22:49:21 +08:00
Account *string `json:"Account"`
2024-09-29 21:12:57 +08:00
Nickname *string `json:"nickname"`
Avatar *string `json:"avatar"`
}
2024-09-30 22:49:21 +08:00
type LoginTokenVo struct {
jwt.RegisteredClaims
2024-10-03 01:09:14 +08:00
Sn string `json:"sn"`
AccessToken string `json:"accessToken"`
Platform string `json:"platform"`
2024-09-30 22:49:21 +08:00
}
func (vo *LoginTokenVo) SetExtByPlatform(platform string) *LoginTokenVo {
switch platform {
case "web":
{
vo.Platform = "web"
vo.ExpiresAt = jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 7))
}
case "android":
{
vo.Platform = "android"
vo.ExpiresAt = jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 30))
}
case "ios":
{
vo.Platform = "ios"
vo.ExpiresAt = jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 30))
}
default:
{
vo.Platform = "web"
vo.ExpiresAt = jwt.NewNumericDate(time.Now().Add(time.Hour * 7 * 30))
}
}
return vo
}