View Source Bonfire.Me.Accounts (Bonfire v0.9.10-classic-beta.169)
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
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{}}
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{}}
@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{}
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{}}
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
Deletes the given account - use enqueue_delete/1
instead.
Examples
iex> delete(%Account{})
:ok
iex> delete("some_account_id")
:ok
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"}
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
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{}}
request_confirm_email(params_or_changeset_or_form_or_account, opts \\ [])
View SourceRequests 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{}}
Requests a password reset to be sent for the account.
Examples
> request_forgot_password(%{email: "test@example.com"})
{:ok, :resent, %Account{}}
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{}}