2023-11-01 23:21:12 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2024-01-05 03:50:33 +03:00
|
|
|
var ErrEmptyPassword = errors.New("empty password")
|
2023-11-01 23:21:12 +03:00
|
|
|
|
|
|
|
type User struct {
|
|
|
|
Model
|
2024-01-05 03:50:33 +03:00
|
|
|
Username string `gorm:"unique" json:"username"`
|
|
|
|
Email string `gorm:"unique" json:"email"`
|
|
|
|
Password string `json:"-"`
|
|
|
|
Experience int
|
|
|
|
Games []*GameCursor
|
2024-01-21 02:20:59 +03:00
|
|
|
Role UserRole
|
2023-11-01 23:21:12 +03:00
|
|
|
}
|
2024-01-21 02:20:59 +03:00
|
|
|
|
|
|
|
func (u *User) HasRole(role UserRole) bool {
|
|
|
|
return u.Role >= role
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserRole int
|
|
|
|
|
|
|
|
const (
|
|
|
|
RoleUser UserRole = iota
|
|
|
|
RoleCreator
|
|
|
|
RoleAdmin
|
|
|
|
)
|