Openmaize v0.16.1 Openmaize.Confirm
Module to help with email confirmation.
This module can be used for account confirmation by email or for resetting a password.
See the documentation for add_confirm_token
and add_reset_token
in
the Openmaize.DB module for details about creating the token.
Summary
Functions
Function to confirm a user’s email address
Function to authenticate a user when resetting the password
Functions
Function to confirm a user’s email address.
Options
There are four options:
- key_expires_after - the length, in minutes, that the token is valid for
- the default is 120 minutes (2 hours)
- unique_id - the identifier in the query string, or the parameters
- the default is :email
- mail_function - the emailing function that you need to define
- redirects - if Openmaize should handle the redirects or not
- the default true
Examples
First, define a get "/confirm"
route in the web/router.ex file.
Then, in the controller file, import Openmaize.Confirm
and run the
following command:
plug :confirm_email, [mail_function: &Mailer.send_receipt/1] when action in [:confirm]
This command will be run when the user accesses the confirm
route.
There is no need to write a confirm function in your controller.
Function to authenticate a user when resetting the password.
See the documentation for confirm_email
for details about the available
options.
Reset password form
This function is to be used with the reset
post request. For the
reset
get request, you need to render a form with the name “user”,
using [as: :user]
if you are using Phoenix’s form_for
function,
which contains values for the password, email and key (the email and
key should be hidden inputs).
Any password validation needs to be done on the front-end.
Examples
First, define a post "/reset", SomeController, :reset_password
route
in the web/router.ex file. Then, in the controller file, import Openmaize.Confirm
and run the following command:
plug :reset_password, [mail_function: &Mailer.send_receipt/1] when action in [:reset_password]
This command will be run when the user sends the form with the data to
reset the password. There is no need to write a reset_password function
in your controller, but you will need to write a function to handle the
get "/reset"
request, that is, to render the form to reset the password.