-
Notifications
You must be signed in to change notification settings - Fork 30
Email confirmation
This page gives an overview of the Openmaize.ConfirmEmail and Openmaize.ResetPassword plugs.
If you have setup your app using mix openmaize.phx --confirm
, most of the functions needed
to implement email confirmation will be ready. However, you will still need to create an Email
module yourself, using an email library of your choice. See the example below for information
about how to do this with Bamboo.
The processes of confirming the user's email address and of resetting the password are mostly
the same as each other and are shown below (in this guide, the user_controller and password_reset_controller
are files created by the mix openmaize.phx --confirm
command):
- A key is created and a link containing the key is sent to the user
- with email confirmation, this is done when creating the user in the user_controller
- when resetting the password, this is done in the create function in the password_reset_controller
- The user clicks on the link to confirm his / her email
- this will send the user to the
confirm_email
function in the session_controller or theedit
function in the password_reset_controller
- this will send the user to the
- The key is checked by the Openmaize.ConfirmEmail or Openmaize.ResetPassword plug
- if the key is correct and still valid, an
openmaize_info
message is added to theconn
- if the key is invalid, an
openmaize_error
message is added to theconn
- if the key is correct and still valid, an
- The user is redirected to the login page, or an info / error message is sent to the user
This example app shows you how you can use Bamboo, with Bamboo.SMTPAdapter, to handle emailing the users.
The relevant files to look at are:
- mix.exs
-
:bamboo
and:bamboo_smtp
are added to the deps
-
- lib/email.ex
- the main email module - containing the
ask_confirm/2
,ask_reset/2
andreceipt_confirm/1
functions
- the main email module - containing the
- lib/welcome/mailer.ex
- a simple module that provides the
deliver_now
anddeliver_later
functions.
- a simple module that provides the
- config/config.exs
- main configuration
- config/test.exs
- test configuration