# `Lightning.Accounts.User`
[🔗](https://github.com/OpenFn/lightning/blob/main/lib/lightning/accounts/user.ex#L1)

The User model.

# `t`

```elixir
@type t() :: %Lightning.Accounts.User{
  __meta__: term(),
  backup_codes: term(),
  confirmed: 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_totp: term()
}
```

# `changeset`

A user changeset for creating a user.

`confirmed: true` confirms the email; nothing unconfirms one.

# `confirm_changeset`

Confirms the account by setting `confirmed_at`.

# `core_contributor?`

```elixir
@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`

A user changeset for changing a user's details, with the same rules as
`changeset/2`. A password that is already the user's changes nothing.

# `email_changeset`

A user changeset for changing the email.

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

# `github_token_changeset`

# `info_changeset`

A user changeset for basic information:

- first_name
- last_name
- contact_preference

# `langfuse_persona`

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

Returns the Langfuse persona string for a user.

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

# `password_changeset`

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`

# `remove_github_token_changeset`

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

# `scheduled_deletion_changeset`

A user changeset for changing the scheduled_deletion property.

# `superuser_registration_changeset`

```elixir
@spec superuser_registration_changeset(
  :invalid
  | %{optional(:__struct__) =&gt; none(), optional(atom() | binary()) =&gt; 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`

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?`

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`

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

# `validate_email`

# `validate_email_exists`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
