Phauxth v0.10.2 Phauxth.Confirm.PassReset

Confirm a user and reset the password.

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 lines to the web/router.ex file (for a html app):

resources "/password_resets", PasswordResetController, only: [:new, :create]
get "/password_resets/edit", PasswordResetController, :edit
put "/password_resets/update", PasswordResetController, :update

and for an api, add:

post "/password_resets/create", PasswordResetController, :create
put "/password_resets/update", PasswordResetController, :update

Then add the following to the password_reset_controller.ex update function:

def update(conn, %{"password_reset" => params}) do
  case Phauxth.Confirm.PassReset.verify(params) do
    {:ok, user} -> handle_successful_password_reset
    {:error, message} -> handle_error
  end
end

In handle_successful_password_reset, you still need to update the database, setting the new value for the password hash, and send an email to the user, stating that the password reset was successful.

Summary

Functions

Function to confirm the user by checking the token

Check the confirmation key

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

Functions

check_confirm(arg1)

Function to confirm the user by checking the token.

check_key(user, key, valid_secs)

Check the confirmation key.

log(arg1, user_id, ok_log)

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