wip: jwt
This commit is contained in:
@ -1,14 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"loveuer/utodo/internal/model/enum"
|
||||
"loveuer/utodo/pkg/jwt"
|
||||
"loveuer/utodo/pkg/sqlType"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id int64 `json:"id" gorm:"column:id,primaryKey"`
|
||||
CreatedAt int64 `json:"created_at" gorm:"column:created_at,autoCreateTime:milli"`
|
||||
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at,autoUpdateTime:milli"`
|
||||
DeletedAt int64 `json:"deleted_at" gorm:"column:deleted_at"`
|
||||
Username string `json:"username" gorm:"column:username;type:varchar(255);not null"`
|
||||
Nickname string `json:"nickname" gorm:"column:nickname;type:varchar(255);not null"`
|
||||
Password string `json:"-" gorm:"column:password;type:varchar(255);not null"`
|
||||
Avatar string `json:"avatar" gorm:"column:avatar;type:varchar(32);not null"`
|
||||
Phone string `json:"phone" gorm:"column:phone;type:varchar(16);not null"`
|
||||
Email string `json:"email" gorm:"column:email;type:varchar(255);not null"`
|
||||
Id int64 `json:"id" gorm:"column:id;primaryKey"`
|
||||
CreatedAt int64 `json:"created_at" gorm:"column:created_at;autoCreateTime:milli"`
|
||||
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:milli"`
|
||||
DeletedAt int64 `json:"deleted_at" gorm:"column:deleted_at"`
|
||||
Username string `json:"username" gorm:"column:username;type:varchar(255);not null"`
|
||||
Nickname string `json:"nickname" gorm:"column:nickname;type:varchar(255);not null"`
|
||||
Password string `json:"-" gorm:"column:password;type:varchar(255);not null"`
|
||||
ResetPassword uint8 `json:"reset_password" gorm:"column:reset_password;type:tinyint(1);default:0"`
|
||||
Avatar string `json:"avatar" gorm:"column:avatar;type:varchar(32);not null"`
|
||||
Phone string `json:"phone" gorm:"column:phone;type:varchar(16);not null"`
|
||||
Email string `json:"email" gorm:"column:email;type:varchar(255);not null"`
|
||||
TwoFactor enum.TwoFactor `json:"two_factor" gorm:"column:two_factor;type:varchar(16)"` // 2fa type
|
||||
Roles sqlType.SliceStr[enum.UserRole] `json:"roles" gorm:"column:roles;not null"`
|
||||
LastLoginAt int64 `json:"last_login_at" gorm:"column:last_login_at"`
|
||||
}
|
||||
|
||||
func UserJwtPayload(u *User) map[string]any {
|
||||
return map[string]any{
|
||||
"id": u.Id,
|
||||
"username": u.Username,
|
||||
"nickname": u.Nickname,
|
||||
"roles": u.Roles,
|
||||
"last_login_at": u.LastLoginAt,
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
UserJWT = jwt.New(
|
||||
jwt.WithPayloadFn(UserJwtPayload),
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user