52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package dto
|
|
|
|
import (
|
|
"github.com/golang-jwt/jwt/v5"
|
|
"time"
|
|
)
|
|
|
|
type UserVO struct {
|
|
Sn string `json:"sn"`
|
|
Token string `json:"token"`
|
|
Platform string `json:"platform"`
|
|
|
|
Account *string `json:"Account"`
|
|
Nickname *string `json:"nickname"`
|
|
Avatar *string `json:"avatar"`
|
|
}
|
|
|
|
type LoginTokenVo struct {
|
|
jwt.RegisteredClaims
|
|
|
|
Sn string `json:"sn"`
|
|
AccessToken string `json:"accessToken"`
|
|
Platform string `json:"platform"`
|
|
}
|
|
|
|
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
|
|
}
|