package models import ( "time" "git.secnex.io/secnex/certman/utils" "github.com/google/uuid" "gorm.io/gorm" ) type User struct { ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"` Username string `json:"username" gorm:"not null;unique"` Email string `json:"email" gorm:"not null;unique"` Password string `json:"password" gorm:"not null"` ExternalID *string `json:"external_id" gorm:"unique"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"` DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"` OrganizationsCreated []*Organization `json:"organizations_created" gorm:"foreignKey:CreatedBy"` OrganizationsUpdated []*Organization `json:"organizations_updated" gorm:"foreignKey:UpdatedBy"` // Members of organizations Organizations []*Organization `json:"organizations" gorm:"many2many:organization_members;"` } func (u *User) TableName() string { return "users" } func (u *User) BeforeCreate(tx *gorm.DB) (err error) { u.ID = uuid.New() u.Password, err = utils.HashPassword(u.Password, utils.DefaultParams) if err != nil { return err } return }