Mirage.Accounts (mirage v0.76.0)

The Accounts context.

Link to this section Summary

Functions

Emulates that the email will change without actually changing it in the database.

Returns an %Ecto.Changeset{} for changing the user email.

Returns an %Ecto.Changeset{} for changing the user password.

Updates a user's profile fields like name and bio.

Returns an %Ecto.Changeset{} for tracking user changes.

Updates a user's settings fields.

Confirms a user by the given token.

Deletes the signed token with the given context.

Delivers the update email instructions to the given user.

Delivers the confirmation email instructions to the given user.

Delivers the reset password email to the given user.

Generates a mastodon user token.

Generates a session token.

Gets the first user.

Gets a single user.

Gets a user by email.

Gets a user by email and password.

Gets the user by reset password token.

Gets the user with the given signed token.

Registers a user.

Resets the user password.

Updates the user email using the given token.

Updates the user password.

Updates a user's profile fields like name and bio.

Updates a user's profile fields like name and bio.

Link to this section Functions

Link to this function

apply_user_email(user, password, attrs)

Emulates that the email will change without actually changing it in the database.

Examples

iex> apply_user_email(user, "valid password", %{email: ...})
{:ok, %User{}}

iex> apply_user_email(user, "invalid password", %{email: ...})
{:error, %Ecto.Changeset{}}
Link to this function

change_user_email(user, attrs \\ %{})

Returns an %Ecto.Changeset{} for changing the user email.

Examples

iex> change_user_email(user)
%Ecto.Changeset{data: %User{}}
Link to this function

change_user_password(user, attrs \\ %{})

Returns an %Ecto.Changeset{} for changing the user password.

Examples

iex> change_user_password(user)
%Ecto.Changeset{data: %User{}}
Link to this function

change_user_profile(user, attrs \\ %{})

Updates a user's profile fields like name and bio.

Link to this function

change_user_registration(user, attrs \\ %{})

Returns an %Ecto.Changeset{} for tracking user changes.

Examples

iex> change_user_registration(user)
%Ecto.Changeset{data: %User{}}
Link to this function

change_user_settings(user, attrs \\ %{})

Updates a user's settings fields.

Link to this function

confirm_user(token)

Confirms a user by the given token.

If the token matches, the user account is marked as confirmed and the token is deleted.

Link to this function

delete_session_token(token)

Deletes the signed token with the given context.

Link to this function

deliver_update_email_instructions(user, current_email, update_email_url_fun)

Delivers the update email instructions to the given user.

Examples

iex> deliver_update_email_instructions(user, current_email, &Routes.user_update_email_url(conn, :edit, &1))
{:ok, %{to: ..., body: ...}}
Link to this function

deliver_user_confirmation_instructions(user, confirmation_url_fun)

Delivers the confirmation email instructions to the given user.

Examples

iex> deliver_user_confirmation_instructions(user, &Routes.user_confirmation_url(conn, :edit, &1))
{:ok, %{to: ..., body: ...}}

iex> deliver_user_confirmation_instructions(confirmed_user, &Routes.user_confirmation_url(conn, :edit, &1))
{:error, :already_confirmed}
Link to this function

deliver_user_reset_password_instructions(user, reset_password_url_fun)

Delivers the reset password email to the given user.

Examples

iex> deliver_user_reset_password_instructions(user, &Routes.user_reset_password_url(conn, :edit, &1))
{:ok, %{to: ..., body: ...}}
Link to this function

generate_mastodon_user_token(user, token)

Generates a mastodon user token.

Link to this function

generate_user_session_token(user)

Generates a session token.

Link to this function

get_mastodon_user_token(user)

Gets the first user.

Examples

iex> get_user!()
%User{}

iex> get_user!()
** (Ecto.NoResultsError)

Gets a single user.

Raises Ecto.NoResultsError if the User does not exist.

Examples

iex> get_user!(123)
%User{}

iex> get_user!(456)
** (Ecto.NoResultsError)
Link to this function

get_user_by_email(email)

Gets a user by email.

Examples

iex> get_user_by_email("foo@example.com")
%User{}

iex> get_user_by_email("unknown@example.com")
nil
Link to this function

get_user_by_email_and_password(email, password)

Gets a user by email and password.

Examples

iex> get_user_by_email_and_password("foo@example.com", "correct_password")
%User{}

iex> get_user_by_email_and_password("foo@example.com", "invalid_password")
nil
Link to this function

get_user_by_reset_password_token(token)

Gets the user by reset password token.

Examples

iex> get_user_by_reset_password_token("validtoken")
%User{}

iex> get_user_by_reset_password_token("invalidtoken")
nil
Link to this function

get_user_by_session_token(token)

Gets the user with the given signed token.

Link to this function

register_user(attrs)

Registers a user.

Examples

iex> register_user(%{field: value})
{:ok, %User{}}

iex> register_user(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

register_user_with_key(attrs, arg)

Link to this function

reset_user_password(user, attrs)

Resets the user password.

Examples

iex> reset_user_password(user, %{password: "new long password", password_confirmation: "new long password"})
{:ok, %User{}}

iex> reset_user_password(user, %{password: "valid", password_confirmation: "not the same"})
{:error, %Ecto.Changeset{}}
Link to this function

update_mastodon_user_token(user_token, token)

Link to this function

update_user_email(user, token)

Updates the user email using the given token.

If the token matches, the user email is updated and the token is deleted. The confirmed_at date is also updated to the current time.

Link to this function

update_user_password(user, password, attrs)

Updates the user password.

Examples

iex> update_user_password(user, "valid password", %{password: ...})
{:ok, %User{}}

iex> update_user_password(user, "invalid password", %{password: ...})
{:error, %Ecto.Changeset{}}
Link to this function

update_user_profile(user, attrs \\ %{})

Updates a user's profile fields like name and bio.

Link to this function

update_user_settings(user, attrs \\ %{})

Updates a user's profile fields like name and bio.