You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
687 B

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"`
}