Phauxth v0.12.1-rc.0 Phauxth.Confirm View Source

Module to provide user confirmation.

This Plug can be used to provide user confirmation by email, phone, or any other method.

Options

There are two options:

  • identifier - how the user is identified in the confirmation request

    • this should be an atom, and the default is :email
  • key_validity - the length, in minutes, that the token is valid for

    • the default is 60 minutes (1 hour)

Examples

Add the following line to the web/router.ex file:

get "/new", ConfirmController, :new

Then add the following to the confirm_controller.ex new function:

def new(conn, params) do
  case Phauxth.Confirm.verify(params, MyApp.Accounts) do
    {:ok, user} ->
      Accounts.confirm_user(user)
      message = "Your account has been confirmed"
      Message.confirm_success(user.email)
      handle_success(conn, message, session_path(conn, :new))
    {:error, message} ->
      handle_error(conn, message, session_path(conn, :new))
  end
end

In this example, the Accounts.confirm_user function updates the database, setting the confirmed_at value to the current time.

Link to this section Summary

Functions

Function to confirm the user by checking the token

Check the confirmation key

Generate a link containing a user-identifier and the confirmation token

Generate a confirmation token

Print out the log message and return {:ok, user} or {:error, message}

Verify the confirmation key

Link to this section Functions

Link to this function check_confirm(arg1, user_data) View Source

Function to confirm the user by checking the token.

Link to this function check_key(user, key, valid_secs) View Source

Check the confirmation key.

Link to this function gen_link(user_id, key, identifier \\ :email) View Source

Generate a link containing a user-identifier and the confirmation token.

Generate a confirmation token.

Link to this function log(arg1, user_id, ok_log) View Source

Print out the log message and return {:ok, user} or {:error, message}.

Link to this function verify(params, user_data, opts \\ []) View Source

Verify the confirmation key.