Lightning.Accounts.User (Lightning v2.16.8)

View Source

The User model.

Summary

Functions

Confirms the account by setting confirmed_at.

Returns true when the user's email is on the @openfn.org domain.

A user changeset for user details

A user changeset for changing the email.

Returns true if the user has a local password set.

A user changeset for basic information

Returns the Langfuse persona string for a user.

A user changeset for changing the password.

A user changeset for changing the scheduled_deletion property.

A changeset for registering a user via SSO. No password is required; the account is confirmed immediately at registration time.

A superuser changeset for registration.

A user changeset for registration.

Verifies the password.

Validates the current password otherwise adds an error to the changeset.

Types

t()

@type t() :: %Lightning.Accounts.User{
  __meta__: term(),
  backup_codes: term(),
  confirmed_at: term(),
  contact_preference: term(),
  credentials: term(),
  disabled: term(),
  email: term(),
  first_name: term(),
  github_oauth_token: term(),
  hashed_password: term(),
  id: Ecto.UUID.t() | nil,
  inserted_at: term(),
  last_name: term(),
  mfa_enabled: term(),
  oauth_clients: term(),
  password: term(),
  preferences: term(),
  project_users: term(),
  projects: term(),
  role: term(),
  scheduled_deletion: term(),
  support_user: term(),
  updated_at: term(),
  user_identities: term(),
  user_totp: term()
}

Functions

changeset(user, attrs)

confirm_changeset(user)

Confirms the account by setting confirmed_at.

core_contributor?(arg1)

@spec core_contributor?(t()) :: boolean()

Returns true when the user's email is on the @openfn.org domain.

Used to derive Langfuse tracking flags (metrics_opt_in / persona) when making AI chat calls to Apollo.

details_changeset(user, attrs)

A user changeset for user details:

  • email
  • first_name
  • last_name
  • role

email_changeset(user, attrs)

A user changeset for changing the email.

It requires the email to change otherwise an error is added.

github_token_changeset(user, attrs)

has_password?(user)

Returns true if the user has a local password set.

SSO-only users have no password (hashed_password is nil) until they set one via the password reset flow or the profile page.

info_changeset(user, attrs)

A user changeset for basic information:

  • first_name
  • last_name
  • contact_preference

langfuse_persona(user)

@spec langfuse_persona(t()) :: String.t()

Returns the Langfuse persona string for a user.

"core-contributor" for @openfn.org users, "user" otherwise.

password_changeset(user, attrs, opts \\ [])

A user changeset for changing the password.

Options

  • :hash_password - Hashes the password so it can be stored securely in the database and ensures the password field is cleared to prevent leaks in the logs. If password hashing is not needed and clearing the password field is not desired (like when using this changeset for validations on a LiveView form), this option can be set to false. Defaults to true.

preferences_changeset(user, attrs)

remove_github_token_changeset(user)

@spec remove_github_token_changeset(t()) :: Ecto.Changeset.t()

scheduled_deletion_changeset(user, attrs)

A user changeset for changing the scheduled_deletion property.

sso_registration_changeset(user, attrs)

A changeset for registering a user via SSO. No password is required; the account is confirmed immediately at registration time.

superuser_registration_changeset(attrs, opts \\ [])

@spec superuser_registration_changeset(
  :invalid
  | %{optional(:__struct__) => none(), optional(atom() | binary()) => any()},
  keyword()
) :: Ecto.Changeset.t()

A superuser changeset for registration.

It is important to validate the length of both email and password. Otherwise databases may truncate the email without warnings, which could lead to unpredictable or insecure behaviour. Long passwords may also be very expensive to hash for certain algorithms.

Options

  • :hash_password - Hashes the password so it can be stored securely in the database and ensures the password field is cleared to prevent leaks in the logs. If password hashing is not needed and clearing the password field is not desired (like when using this changeset for validations on a LiveView form), this option can be set to false. Defaults to true.

user_registration_changeset(attrs, opts \\ [])

A user changeset for registration.

It is important to validate the length of both email and password. Otherwise databases may truncate the email without warnings, which could lead to unpredictable or insecure behaviour. Long passwords may also be very expensive to hash for certain algorithms.

Options

  • :hash_password - Hashes the password so it can be stored securely in the database and ensures the password field is cleared to prevent leaks in the logs. If password hashing is not needed and clearing the password field is not desired (like when using this changeset for validations on a LiveView form), this option can be set to false. Defaults to true.

valid_password?(arg1, password)

Verifies the password.

If there is no user or the user doesn't have a password, we call Bcrypt.no_user_verify/0 to avoid timing attacks.

validate_current_password(changeset, password)

Validates the current password otherwise adds an error to the changeset.

validate_email(changeset)

validate_email_exists(changeset)