Phauxth v0.14.0 Phauxth.Confirm.PassReset View Source

Confirm a user and reset the password.

Options

There is one option:

  • 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 (this example is for a html app):

def update(conn, %{"password_reset" => params}) do
  case Phauxth.Confirm.PassReset.verify(params, MyApp.Accounts, key_validity: 20) do
    {:ok, user} ->
      Accounts.update_user(user, params)
      Message.reset_success(user.email)
      message = "Your password has been reset"
      configure_session(conn, drop: true)
      |> handle_success(message, session_path(conn, :new))
    {:error, message} ->
      conn
      |> put_flash(:error, message)
      |> render("edit.html", email: params["email"], key: params["key"])
  end
end

In this example, the Accounts.update_user function updates the database, setting the password_hash value to the hash for the new password and the reset_token and reset_sent_at values to nil.

Link to this section Summary

Functions

Check the confirmation key

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_key(user, key, valid_secs) View Source

Check the confirmation key.

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

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

Verify the confirmation key.