2024-01-16 01:58:20 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2024-02-14 00:36:23 +00:00
|
|
|
"errors"
|
2024-01-16 01:58:20 +00:00
|
|
|
"gorm.io/gorm"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
gorm.Model
|
2024-02-14 00:06:04 +00:00
|
|
|
FirstName string
|
|
|
|
LastName string
|
2024-01-16 01:58:20 +00:00
|
|
|
Email string `gorm:"unique"`
|
|
|
|
PasswordHash string
|
|
|
|
Role string
|
|
|
|
PublicKeys []PublicKey
|
|
|
|
APIKeys []APIKey
|
|
|
|
Uploads []Upload
|
|
|
|
LastLogin *time.Time
|
|
|
|
LastLoginIP string
|
|
|
|
}
|
2024-02-14 00:36:23 +00:00
|
|
|
|
|
|
|
func (u *User) BeforeUpdate(tx *gorm.DB) error {
|
|
|
|
if len(u.FirstName) == 0 {
|
|
|
|
return errors.New("first name is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(u.LastName) == 0 {
|
|
|
|
return errors.New("last name is empty")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|