Encrypted messaging app
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.

23 lines
678 B

  1. package Models
  2. import (
  3. "gorm.io/gorm"
  4. )
  5. // Prevent updating the email if it has not changed
  6. // This stops a unique constraint error
  7. func (u *User) BeforeUpdate(tx *gorm.DB) (err error) {
  8. if !tx.Statement.Changed("Username") {
  9. tx.Statement.Omit("Username")
  10. }
  11. return nil
  12. }
  13. type User struct {
  14. Base
  15. Username string `gorm:"not null;unique" json:"username"`
  16. Password string `gorm:"not null" json:"password"`
  17. ConfirmPassword string `gorm:"-" json:"confirm_password"`
  18. AsymmetricPrivateKey string `gorm:"not null" json:"asymmetric_private_key"` // Stored encrypted
  19. AsymmetricPublicKey string `gorm:"not null" json:"asymmetric_public_key"`
  20. }