Haytni.ConfirmablePlugin (Haytni v0.6.3) View Source

This plugin ensure that email addresses given by users are valid by sending them an email containing an unique token that they have to return back in order to really be able to use (unlock) their account.

On an email address change, it also warns the user by sending an email to the previous address and requests a confirmation, same as registering, to active in order to validate the change.

Fields:

  • confirmed_at (datetime@utc, nullable, default: NULL): when the account was confirmed else NULL
  • confirmation_sent_at (datetime@utc): when the confirmation was sent
  • confirmation_token (string, nullable, unique, default: NULL): the token to be confirmed if any pending confirmation (else NULL)
  • unconfirmed_email (string, nullable, default: NULL): on email change the new email is stored here until its confirmation

Configuration:

  • reconfirmable (default: true): any email changes have to be confirmed to be applied. Until confirmed, new email is stored in unconfirmed_email column, and copied to email column on successful confirmation

  • confirmation_keys (default: [:email]): the key(s) to be matched before sending a new confirmation

  • confirm_within (default: {3, :day}): delay after which confirmation token is considered as expired (ie the user has to ask for a new one)

    stack Haytni.ConfirmablePlugin,
      reconfirmable: true,
      confirm_within: {3, :day},
      confirmation_keys: [:email],
      confirmation_token_length: 32

Routes:

  • haytni_<scope>_confirmation_path (actions: show, new/create): default path is "/confirmation" but it can be redefined by the :confirmation_path option when calling YourApp.Haytni.routes/1 from your own router (eg: YourApp.Haytni.routes(confirmation_path: "/verification"))

Link to this section Summary

Functions

The translated string to display when the account is already confirmed.

Confirms an account from its (re)confirmation token.

Add changes to user_or_changeset to mark the user as an account to be confirmed

This function converts the parameters received by the controller to request a new confirmation token sent by email to an %Ecto.Changeset{}, a convenient way to perform basic validations, any intermediate handling and casting.

Has the given user been confirmed?

The translated string to display when (re)confirmation is expired

The translated string to display when (re)confirmation token is invalid (meaning matches no one)

The (database) attributes as a keyword-list to update a user as an account to be confirmed

The translated string to display when account is on pending (re)confirmation.

Resend confirmation instructions to an email address (requested by its owner).

The (database) attributes as a keyword-list (field name: new value) to update a user as a confirmed account

Link to this section Functions

Link to this function

alreay_confirmed_message()

View Source

Specs

alreay_confirmed_message() :: String.t()

The translated string to display when the account is already confirmed.

Link to this function

confirm(module, config, token)

View Source

Specs

confirm(
  module :: module(),
  config :: Haytni.ConfirmablePlugin.Config.t(),
  token :: String.t()
) :: {:ok, Haytni.user()} | {:error, String.t()}

Confirms an account from its (re)confirmation token.

Returns {:error, reason} if token is expired or invalid else the (updated) user as {:ok, user}.

Link to this function

confirmation_changeset(user_or_changeset, config)

View Source

Specs

confirmation_changeset(
  user_or_changeset :: Haytni.user() | Ecto.Changeset.t(),
  config :: Haytni.ConfirmablePlugin.Config.t()
) :: Ecto.Changeset.t()

Add changes to user_or_changeset to mark the user as an account to be confirmed

Link to this function

confirmation_request_changeset(config, confirmation_params \\ %{})

View Source

Specs

confirmation_request_changeset(
  config :: Haytni.ConfirmablePlugin.Config.t(),
  confirmation_params :: Haytni.params()
) :: Ecto.Changeset.t()

This function converts the parameters received by the controller to request a new confirmation token sent by email to an %Ecto.Changeset{}, a convenient way to perform basic validations, any intermediate handling and casting.

Specs

confirmed?(user :: Haytni.user()) :: boolean()

Has the given user been confirmed?

Specs

expired_token_message() :: String.t()

The translated string to display when (re)confirmation is expired

Link to this function

find_user(conn, module, config)

View Source

Callback implementation for Haytni.Plugin.find_user/3.

Specs

invalid_token_message() :: String.t()

The translated string to display when (re)confirmation token is invalid (meaning matches no one)

Link to this function

new_confirmation_attributes(config)

View Source

Specs

new_confirmation_attributes(config :: Haytni.ConfirmablePlugin.Config.t()) ::
  Keyword.t()

The (database) attributes as a keyword-list to update a user as an account to be confirmed

Link to this function

on_failed_authentication(user, multi, keywords, module, config)

View Source

Callback implementation for Haytni.Plugin.on_failed_authentication/5.

Link to this function

on_logout(conn, module, config)

View Source

Callback implementation for Haytni.Plugin.on_logout/3.

Link to this function

on_successful_authentication(conn, user, multi, keywords, module, config)

View Source

Callback implementation for Haytni.Plugin.on_successful_authentication/6.

Link to this function

pending_confirmation_message()

View Source

Specs

pending_confirmation_message() :: String.t()

The translated string to display when account is on pending (re)confirmation.

Link to this function

resend_confirmation_instructions(module, config, confirmation_params)

View Source

Specs

resend_confirmation_instructions(
  module :: module(),
  config :: Haytni.ConfirmablePlugin.Config.t(),
  confirmation_params :: Haytni.params()
) :: Haytni.repo_nobang_operation(Haytni.user() | nil)

Resend confirmation instructions to an email address (requested by its owner).

Returns:

  • {:error, changeset} if there is no account matching config.confirmation_keys or if the account is not pending confirmation (changeset.errors will be set according)
  • {:ok, user} if successful

But returned values differ in strict mode (config :haytni, mode: :strict):

  • {:error, changeset} if fields (form) were not filled
  • {:ok, user} if successful or nothing has to be done (meaning there is no account matching config.confirmation_keys or the account is not pending confirmation)
Link to this function

reset_confirmation_attributes()

View Source

Specs

reset_confirmation_attributes() :: Keyword.t()

The (database) attributes as a keyword-list (field name: new value) to update a user as a confirmed account

Link to this function

validate_password(changeset, module, config)

View Source

Callback implementation for Haytni.Plugin.validate_password/3.

Link to this function

validate_update_registration(changeset, module, config)

View Source

Callback implementation for Haytni.Plugin.validate_update_registration/3.