|
|
- package Models
-
- import (
- "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("Username") {
- tx.Statement.Omit("Username")
- }
- return nil
- }
-
- type User struct {
- Base
- Username string `gorm:"not null;unique" json:"username"`
- Password string `gorm:"not null" json:"password"`
- ConfirmPassword string `gorm:"-" json:"confirm_password"`
- AsymmetricPrivateKey string `gorm:"not null" json:"asymmetric_private_key"` // Stored encrypted
- AsymmetricPublicKey string `gorm:"not null" json:"asymmetric_public_key"`
- FriendID string `gorm:"not null" json:"public_user_id"` // Stored encrypted
- FriendSymmetricKey string `gorm:"not null" json:"symmetric_key"` // Stored encrypted
- }
|