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.

33 lines
1.4 KiB

  1. package Models
  2. import (
  3. "github.com/gofrs/uuid"
  4. "gorm.io/gorm"
  5. )
  6. // BeforeUpdate prevents updating the username or 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("Username") {
  10. tx.Statement.Omit("Username")
  11. }
  12. if !tx.Statement.Changed("Email") {
  13. tx.Statement.Omit("Email")
  14. }
  15. return nil
  16. }
  17. // User holds user data
  18. type User struct {
  19. Base
  20. Username string `gorm:"not null;unique" json:"username"`
  21. Password string `gorm:"not null" json:"password"`
  22. ConfirmPassword string `gorm:"-" json:"confirm_password"`
  23. Email string ` json:"email"`
  24. AsymmetricPrivateKey string `gorm:"not null" json:"asymmetric_private_key"` // Stored encrypted
  25. AsymmetricPublicKey string `gorm:"not null" json:"asymmetric_public_key"`
  26. SymmetricKey string `gorm:"not null" json:"symmetric_key"` // Stored encrypted
  27. AttachmentID *uuid.UUID ` json:"attachment_id"`
  28. Attachment Attachment ` json:"attachment"`
  29. MessageExpiryDefault MessageExpiry `gorm:"default:no_expiry" json:"-" sql:"type:ENUM('fifteen_min', 'thirty_min', 'one_hour', 'three_hour', 'six_hour', 'twelve_hour', 'one_day', 'three_day', 'no_expiry')"` // Stored encrypted
  30. }