Phauxth v1.0.3 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
Link to this section Functions
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.
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
The following function is an example of using verify in a Phoenix controller.
def create(conn, %{"session" => params}) do
case Phauxth.Login.verify(params, MyApp.Accounts) do
{:ok, user} ->
put_session(conn, :user_id, user.id)
|> configure_session(renew: true)
|> success("You have been logged in", user_path(conn, :index))
{:error, message} ->
error(conn, message, session_path(conn, :new))
end
end
In this example, if the login is successful, the user is added to the session, which is then renewed, and then is redirected to the /users page.