package Models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Prevent updating the email if it has not changed
|
|
// This stops a unique constraint error
|
|
func (u *User) BeforeUpdate(tx *gorm.DB) (err error) {
|
|
if !tx.Statement.Changed("Email") {
|
|
tx.Statement.Omit("Email")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type User struct {
|
|
Base
|
|
Email string `gorm:"not null;unique" json:"email"`
|
|
Password string `gorm:"not null" json:"password,omitempty"`
|
|
ConfirmPassword string `gorm:"-" json:"confirm_password"`
|
|
LastLogin *time.Time `json:"last_login"`
|
|
FirstName string `gorm:"not null" json:"first_name"`
|
|
LastName string `gorm:"not null" json:"last_name"`
|
|
}
|