Jumar.Accounts.User (Jumar v0.1.0)

View Source

Every user account in the system.

Summary

Functions

Confirms the account by setting confirmed_at.

A user changeset for changing the email.

A user changeset for changing the password.

A user changeset for registration.

Verifies the password.

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

Types

t()

@type t() :: %Jumar.Accounts.User{
  __meta__: Ecto.Schema.Metadata.t(),
  confirmed_at: DateTime.t() | nil,
  email: String.t() | nil,
  hashed_password: String.t() | nil,
  id: Jumar.Types.TypeId.t() | nil,
  inserted_at: DateTime.t() | nil,
  password: String.t() | nil,
  updated_at: DateTime.t() | nil
}

Functions

confirm_changeset(user)

@spec confirm_changeset(t() | Ecto.Changeset.t()) :: Ecto.Changeset.t()

Confirms the account by setting confirmed_at.

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

@spec email_changeset(
  t(),
  map(),
  Keyword.t()
) :: Ecto.Changeset.t()

A user changeset for changing the email.

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

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

@spec password_changeset(
  t(),
  map(),
  Keyword.t()
) :: Ecto.Changeset.t()

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.

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

@spec registration_changeset(
  t(),
  map(),
  Keyword.t()
) :: Ecto.Changeset.t()

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 behavior. 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.

  • :validate_email - Validates the uniqueness of the email, in case you don't want to validate the uniqueness of the email (like when using this changeset for validations on a LiveView form before submitting the form), this option can be set to false. Defaults to true.

valid_password?(arg1, password)

@spec valid_password?(t(), String.t()) :: boolean()

Verifies the password.

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

validate_current_password(changeset, password)

@spec validate_current_password(Ecto.Changeset.t(), String.t()) :: Ecto.Changeset.t()

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