Authentication
Documentation / Authentication / User Model

User Model

Built-in Model

Runique includes a ready-to-use user model that requires no configuration.

Generated table: eihwaz_users

FieldTypeDescription
idPkPrimary key (i32 by default, i64 with big-pk, Uuid with pk-uuid)
usernameStringUnique username
emailStringEmail address
passwordStringHash (the PasswordConfig's algorithm) — never stored in plain text
is_activeboolAccount active
is_adminboolAdmin rank: panel access, with its own rights (table × column)
is_dirigeantboolDirigeant rank: every right on the project's models
is_superuserboolSuperuser rank: full access
created_atdatetimeCreation timestamp
updated_atdatetimeLast update timestamp
activated_atdatetimeActivation by the owner (empty while the account is pending)

To create the first superuser:

runique create-superuser

i64 or UUID primary key

By default, the primary key is i32. To switch to i64 or Uuid — only one feature at a time, enabling both together is a deliberate compile-time error:

# project Cargo.toml
runique = { version = "4.0.0", features = ["postgres", "big-pk"] }    # Pk = i64
runique = { version = "4.0.0", features = ["postgres", "pk-uuid"] }   # Pk = Uuid (Uuid::now_v7())

The choice must be made before the first migration — see model! DSL & extend! for full details (compatible types, FK constraints, switching mode after the fact).


Account states

eihwaz_users is the only user model: to add fields to it, use extend!{ table: "eihwaz_users", ... }.

Two columns describe an account's state: is_active (is it active?) and activated_at (when did its owner activate it, through the emailed link?).

is_activeactivated_atStateSign-in"Forgot password"
falseemptyPending — created, never activatedRefusedLink that activates the account
truesetActiveAllowedReset link
falsesetDeactivated from the adminRefused"Account blocked" email, no link
trueemptyImpossible — refused by the database——
  • The first activation belongs to the email's owner: an admin can't tick is_active on a pending account.
  • Deactivating and reactivating an account activated before is done from the admin, by an account allowed to. (can_update on users).
  • Changing the password never reactivates a deactivated account.
  • The "forgot password" page answers the same whatever the account's state or existence.
  • To cancel an invitation (pending account), delete the account.

The guarantee "no is_active without activated_at" is set in the database: a CHECK constraint created with the eihwaz_users table, on all three engines. It applies to raw SQL too.

In code, the model implements the RuniqueUser trait:

MethodDescription
can_sign_in()is_active and activated_at set

Admin panel access is read on the signed-in account (request.user): can_access_admin() is true for rank admin, dirigeant or superuser, or for a member of a group that opens the admin. See Middlewares & CurrentUser.