Skip to content

User

The host application's User model, into which Trek injects authentication (Sorcery), roles, theme & locale preferences and the invitation workflow.

Columns added by Trek

ColumnTypeNotes
namestringdisplay name
roleintegerenum, default guest
themeintegerenum, default auto
localestringadmin UI language

Plus the Sorcery authentication columns (email, crypted_password, reset tokens…).

Roles

Trek::Users::Roles defines the role enum and access levels:

ruby
enum :role, { admin: 5, editor: 4, user: 3, reader: 2, guest: 1 }, default: "guest"
  • privileged?true for admin and editor; this is what the default policies check
  • User.human_roles — translated role names for form selects

Themes

Trek::Users::Themes lets each user pick the admin theme:

ruby
enum :theme, { auto: 0, light: 1, dark: 2 }, default: "auto"

User.human_themes returns translated theme names.

Locales

Trek::Users::Locales provides User.human_locales — the available admin UI languages with translated labels, sourced from I18n.available_locales.

Invitations

Trek::Users::Invitable adds a transient send_invite flag: when set on creation, the user receives an invitation email with a password-reset link.

ruby
User.create(email: "new@example.com", role: :editor, send_invite: true)

Validations

Trek::Users::Validations enforces:

  • email — presence, uniqueness, valid format
  • password — minimum 8 characters (on creation or password change)

Scopes

Trek::Users::Scopes adds User.ordered — alphabetical by name, then email.

Form models

Two non-persisted ActiveModel::Model companions handle the auth flows:

  • Trek::UserSessionemail + password, used by the login form
  • Trek::UserPasswordResetemail, looks up the user to send a reset link to

Released under the MIT License.