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

  1. package Models
  2. import (
  3. "time"
  4. "gorm.io/gorm"
  5. )
  6. // Prevent updating the email if it has not changed
  7. // This stops a unique constraint error
  8. func (u *User) BeforeUpdate(tx *gorm.DB) (err error) {
  9. if !tx.Statement.Changed("Email") {
  10. tx.Statement.Omit("Email")
  11. }
  12. return nil
  13. }
  14. type User struct {
  15. Base
  16. Email string `gorm:"not null;unique" json:"email"`
  17. Password string `gorm:"not null" json:"password,omitempty"`
  18. ConfirmPassword string `gorm:"-" json:"confirm_password"`
  19. LastLogin *time.Time `json:"last_login"`
  20. FirstName string `gorm:"not null" json:"first_name"`
  21. LastName string `gorm:"not null" json:"last_name"`
  22. }