View Source Bonfire.Me.Accounts (Bonfire v0.9.10-classic-beta.156)

An account represents a private identity within the system, and can have many User identities (see Bonfire.Me.Accounts). An account usually has an Bonfire.Data.Identity.Email and a Bonfire.Data.Identity.Credential user for login.

Summary

Functions

Checks if signup is allowed based on instance config and provided options.

Changes the email for the current account.

Changes the password for the current account.

Returns a changeset for the given changeset name and parameters.

Confirms an account's email address as valid, usually by providing a confirmation token, or directly by providing an Account.

Confirms an account's email manually, by providing the email address. Only for internal or CLI use.

Counts the number of accounts.

Deletes the given account - use enqueue_delete/1 instead.

Enqueues the deletion of the given account.

Fetches the current account by its ID, returns {:error, :not_found} if the ID is nil.

Returns the account by its email.

Returns the current account by its ID or nil if the ID is nil.

Checks if the instance is invite-only.

Checks if the given user or account is an admin.

Attempts to log in by password and either username or email.

Requests an email confirmation for the account.

Requests a password reset to be sent for the account.

Signs up a new account with the given parameters.

Types

@type changeset_name() :: :change_password | :confirm_email | :login | :signup

Functions

Checks if signup is allowed based on instance config and provided options.

Examples

iex> allow_signup?(%{invite: "invite_code"})
true
Link to this function

change_email(current_account, params_or_changeset, opts \\ [])

View Source

Changes the email for the current account.

Examples

> change_email(%Account{}, %{old_email: "old@example.com", email: "new@example.com"})
{:ok, %Account{}}

> change_email(%Account{}, %Changeset{valid?: false})
{:error, %Changeset{}}
Link to this function

change_password(current_account, params_or_changeset, opts \\ [])

View Source

Changes the password for the current account.

Examples

> change_password(%Account{}, %{old_password: "old", password: "new"})
{:ok, %Account{}}

> change_password(%Account{}, %Changeset{valid?: false})
{:error, %Changeset{}}
Link to this function

change_password(current_account, cs, params, opts)

View Source
Link to this function

changeset(changeset_name, params, opts \\ [])

View Source
@spec changeset(changeset_name(), params :: map(), opts :: Keyword.t()) ::
  Ecto.Changeset.t()

Returns a changeset for the given changeset name and parameters.

Examples

> changeset(:forgot_password, %{})
%Changeset{}

> changeset(:login, %{email: "test@example.com", password: "secret"})
%Changeset{}
Link to this function

confirm_email(account_or_token, opts \\ [])

View Source

Confirms an account's email address as valid, usually by providing a confirmation token, or directly by providing an Account.

Examples

> confirm_email("some_token")
{:ok, %Account{}}

> confirm_email(%Account{})
{:ok, %Account{}}
Link to this function

confirm_email_manually(email)

View Source

Confirms an account's email manually, by providing the email address. Only for internal or CLI use.

Examples

> confirm_email_manually("test@example.com")
{:ok, %Account{}}

Counts the number of accounts.

Examples

iex> count()
42
Link to this function

delete(account, opts \\ [])

View Source

Deletes the given account - use enqueue_delete/1 instead.

Examples

iex> delete(%Account{})
:ok

iex> delete("some_account_id")
:ok
Link to this function

do_signup(cs_or_params, opts)

View Source

Enqueues the deletion of the given account.

Examples

> enqueue_delete(%Account{})
:ok

> enqueue_delete("some_account_id")
:ok

Fetches the current account by its ID, returns {:error, :not_found} if the ID is nil.

Examples

iex> fetch_current(nil)
{:error, :not_found}

> fetch_current("some_id")
{:ok, %Account{id: "some_id"}}

Returns the account by its email.

Examples

> get_by_email("test@example.com")
%Account{email: "test@example.com"}

Returns the current account by its ID or nil if the ID is nil.

Examples

iex> get_current(nil)
nil

> get_current("some_id")
%Account{id: "some_id"}
Link to this function

instance_is_invite_only?()

View Source

Checks if the instance is invite-only.

Examples

> instance_is_invite_only?()
true

Checks if the given user or account is an admin.

Examples

> is_admin?(user)
true

> is_admin?(account)
true
Link to this function

login(params_or_changeset, opts \\ [])

View Source

Attempts to log in by password and either username or email.

Accepts a map of parameters or a LoginFields changeset.

On success, returns {:ok, account, user} if a username was provided and {:ok, account, nil} otherwise. On error, returns {:error, changeset}

Examples

> login(%{email: "test@example.com", password: "secret"})
{:ok, %Account{}, nil}

> login(%{username: "test", password: "secret"})
{:ok, %Account{}, %User{}}

> login(%Changeset{valid?: false})
{:error, %Changeset{}}
Link to this function

login_valid?(user, password)

View Source
Link to this function

make_account(attrs \\ %{}, opts \\ [])

View Source
Link to this function

maybe_redeem_invite(data, opts)

View Source
Link to this function

prepare_signup_opts(opts)

View Source
Link to this function

redeemable_invite?(invite)

View Source
Link to this function

request_confirm_email(params_or_changeset_or_form_or_account, opts \\ [])

View Source

Requests an email confirmation for the account.

Examples

> request_confirm_email(%{email: "test@example.com"})
{:ok, :resent, %Account{}}

> request_confirm_email(%Changeset{valid?: false})
{:error, %Changeset{}}
Link to this function

request_forgot_password(params)

View Source

Requests a password reset to be sent for the account.

Examples

> request_forgot_password(%{email: "test@example.com"})
{:ok, :resent, %Account{}}
Link to this function

signup(params_or_changeset, opts \\ [])

View Source

Signs up a new account with the given parameters.

Examples

> signup(%{email: "test@example.com", password: "secret"})
{:ok, %Account{}}

> signup(%Changeset{valid?: false})
{:error, %Changeset{}}
Link to this function

update_is_admin(user_or_account, make_admin_or_revoke, user \\ nil)

View Source