Phauxth v0.17.0 Phauxth.Confirm.Login View Source

A custom login function which also checks to see if the user’s account has been confirmed yet.

Link to this section Summary

Functions

Check the user is confirmed before checking the password

Verify a user’s password

Link to this section Functions

Link to this function check_pass(user, password, crypto, opts) View Source

Check the user is confirmed before checking the password.

If confirmed_at: nil is in the user struct, this function will return {:error, message}. Otherwise, it will run the default check_pass function.

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

Verify a user’s password.

Check the user’s password, and return {:ok, user} if login is successful or {:error, message} if there is an error.

If login is successful, you need to either add the user to the session, by running put_session(conn, :user_id, id), or send an api token to the user.

Options

There are two options for the verify function:

  • crypto - the password hashing module to use

    • the default is Comeonin.Bcrypt
  • log_meta - additional custom metadata for Phauxth.Log

    • this should be a keyword list

The check_pass function also has options. See the documentation for the password hashing module you are using for details.

Examples

In the example below, verify is called within the create function in the session controller.

use Phauxth.Login

def create(conn, %{"session" => params}) do
  case verify(params, MyApp.Accounts) do
    {:ok, user} -> handle_successful_login
    {:error, message} -> handle_error
  end
end