Phauxth v0.16.0 Phauxth.Confirm.PassReset View Source

Confirm a user in order to reset the password.

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, {conn, 15}) do
    {:ok, user} ->
      Accounts.update_user(user, params)
      Message.reset_success(user.email)
      configure_session(conn, drop: true)
      |> put_flash(:info, "Your password has been reset")
      |> redirect(to: 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_sent_at value to nil.

Link to this section Summary

Functions

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

Verify the confirmation key and get the user data from the database

Link to this section Functions

Link to this function get_user(key_source, arg) View Source

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

Link to this function verify(arg1, user_context, arg3) View Source

Verify the confirmation key and get the user data from the database.

In the third argument, the key_source is either conn or the name of the endpoint module, and the max_age is the maximum age of the key, in seconds.