SecNex

Users

User model in ClueQuest Go SDK

Schema

FieldTypeDescriptionExtra Info
IDuuid.UUIDUnique identifier for the user.Primary Key
FirstNamestringFirst name of the user.not null
LastNamestringLast name of the user.not null
UsernamestringUsername of the user.unique, not null
EmailstringEmail address of the user.unique, not null
PasswordstringHashed password of the user.unique, not null
CreatedAttime.TimeTimestamp of when the user was created.Set automatically to current time at creation
UpdatedAttime.TimeTimestamp of the last update to the user.Set automatically to current time at update
DeletedAtgorm.DeletedAtTimestamp of when the user was deleted (if applicable).It is needed for soft deletion.

Model

user.go
type User struct {
	ID        uuid.UUID      `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()" json:"id"`
	FirstName string         `gorm:"not null" json:"first_name"`
	LastName  string         `gorm:"not null" json:"last_name"`
	Username  string         `gorm:"unique;not null" json:"username"`
	Email     string         `gorm:"unique;not null" json:"email"`
	Password  string         `gorm:"unique;not null" json:"-"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

	Organizations []Organization `gorm:"many2many:user_organizations;" json:"organizations,omitempty"`

	CreatedOrganization []Organization `gorm:"foreignKey:CreatedBy" json:"created_organization,omitempty"`

	CreatedQuiz []Quiz `gorm:"foreignKey:CreatedBy" json:"created_quiz,omitempty"`
	UpdatedQuiz []Quiz `gorm:"foreignKey:UpdatedBy" json:"updated_quiz,omitempty"`
}

Relationships

  • CreatedOrganizations: One-to-many relationship with the Organization model. A user can create multiple organizations.
  • Organizations: Many-to-many relationship with the Organization model through the user_organizations join table. A user can belong to multiple organizations.

Security

The Password field stores the hashed password of the user and is excluded from JSON serialization for security reasons. Always ensure that passwords are properly hashed before storing them in the database. We use Argon2 for password hashing in ClueQuest SDK.