Haytni v0.6.1 Haytni.ConfirmablePlugin 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 elseNULL
- 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 (elseNULL
) - 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 confirmationconfirmation_keys
(default:~W[email]a
): the key(s) to be matched before sending a new confirmationconfirm_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: ~W[email]a, 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
Callback implementation for Haytni.Plugin.find_user/3
.
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
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_logout/2
.
Callback implementation for Haytni.Plugin.on_successful_authentication/5
.
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
Callback implementation for Haytni.Plugin.validate_password/2
.
Callback implementation for Haytni.Plugin.validate_update_registration/2
.
Link to this section Functions
Specs
alreay_confirmed_message() :: String.t()
The translated string to display when the account is already confirmed.
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}
.
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
confirmation_request_changeset(config, confirmation_params \\ %{})
View SourceSpecs
confirmation_request_changeset( config :: Haytni.ConfirmablePlugin.Config.t(), confirmation_params :: %{optional(String.t()) => String.t()} ) :: 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
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)
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
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_logout/2
.
Callback implementation for Haytni.Plugin.on_successful_authentication/5
.
Specs
pending_confirmation_message() :: String.t()
The translated string to display when account is on pending (re)confirmation.
resend_confirmation_instructions(module, config, confirmation_params)
View SourceSpecs
resend_confirmation_instructions( module :: module(), config :: Haytni.ConfirmablePlugin.Config.t(), confirmation_params :: %{optional(String.t()) => String.t()} ) :: {:ok, nil | Haytni.user()} | {:error, Ecto.Changeset.t()}
Resend confirmation instructions to an email address (requested by its owner).
Returns:
{:error, changeset}
if there is no account matchingconfig.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 matchingconfig.confirmation_keys
or the account is not pending confirmation)
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
Callback implementation for Haytni.Plugin.validate_password/2
.
Callback implementation for Haytni.Plugin.validate_update_registration/2
.