38 lines
929 B
Go
38 lines
929 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
const (
|
|
RoleAdmin = "admin"
|
|
RoleUser = "user"
|
|
)
|
|
|
|
type User struct {
|
|
ID string `gorm:"primaryKey"`
|
|
Name string `gorm:"size:120;index"`
|
|
Email string `gorm:"size:320;uniqueIndex;not null"`
|
|
PasswordHash string `gorm:"size:255;not null"`
|
|
EmailVerified bool `gorm:"not null;default:false"`
|
|
Role string `gorm:"size:32;index;not null;default:user"`
|
|
Properties UserProperties `gorm:"foreignKey:UserId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func (user *User) BeforeCreate(tx *gorm.DB) (err error) {
|
|
// UUID version 4
|
|
user.ID = uuid.NewString()
|
|
return
|
|
}
|
|
|
|
type UserProperties struct {
|
|
UserId string `json:"user_id" gorm:"uniqueIndex"`
|
|
Lang string `json:"lang"`
|
|
Dark bool `json:"dark"`
|
|
}
|