Coherence.SessionController (Coherence v0.8.0)

Handle the authentication actions.

Module used for the session controller when the parent project does not generate controllers. Most of the work is done by the Coherence.SessionControllerBase inclusion.

Summary

Types

@type conn() :: Plug.Conn.t()
@type params() :: map()
@type schema() :: Ecto.Schema.t()

Functions

Link to this function

confirmed_access?(user)

Check if the user is confirmed.

Link to this function

create(conn, params)

@spec create(conn(), params()) :: conn()

Login the user.

Find the user based on the login_field. Hash the given password and verify it matches the value stored in the database. Login proceeds only if the following other conditions are satisfied:

  • Confirmation is enabled and the user has been confirmed.
  • Lockable is enabled and the user is not locked.

If the Trackable option is enabled, the trackable fields are update.

If the provided password is not correct, and the lockable option is enabled check to see if the maximum login attempts threshold is exceeded. If so, lock the account.

If the rememberable option is enabled, create a new series and rememberable token, create a new cookie and update the database.

Link to this function

delete(conn, params)

@spec delete(conn(), params()) :: conn()

Logout the user.

Delete the user's session, track the logout and delete the rememberable cookie.

Link to this function

delete_expired_tokens!(repo)

Link to this function

do_lockable(conn, login_field, opts, bool)

Link to this function

do_valid_login(user, conn, params, opts)

Link to this function

failed_login(conn, user, arg3)

Link to this function

gen_cookie(user_id, series, token)

Link to this function

get_invalid_login!(repo, user_id, series, token)

Link to this function

get_login_cookie(conn)

@spec get_login_cookie(conn()) :: String.t()

Retrieve the login cookie.

Link to this function

get_login_user(login_field, login, params)

Get the user from the database.

Link to this function

get_rememberables(id)

@spec get_rememberables(integer()) :: [schema()]

Fetch a rememberable database record.

Link to this function

get_valid_login!(repo, user_id, series, token)

Link to this function

new(conn, params)

@spec new(conn(), params()) :: conn()

Render the login form.

Link to this function

put_flash_inactive_user(conn)

Link to this function

rememberable_callback(conn, id, series, token, opts)

@spec rememberable_callback(conn(), integer(), String.t(), String.t(), keyword()) ::
  conn()

Callback for the authenticate plug.

Validate the rememberable cookie. If valid, generate a new token, keep the same series number. Update the rememberable database with the new token. Save the new cookie.

Link to this function

reset_failed_attempts(conn, user, arg3)

@spec reset_failed_attempts(conn(), Ecto.Schema.t(), boolean()) :: conn()
Link to this function

save_login_cookie(conn, id, series, token, opts \\ [])

@spec save_login_cookie(conn(), integer(), String.t(), String.t(), keyword()) ::
  conn()

Save the login cookie.

Link to this function

save_rememberable(conn, user, none)

Link to this function

track_login(conn, user, trackable?, trackable_table?)

Link to this function

user_active?(user)

Link to this function

valid_user_login?(user, arg2)

Validate a user' login.

Link to this function

validate_login(user_id, series, token)

@spec validate_login(integer(), String.t(), String.t()) ::
  {:ok, schema()} | {:error, atom()}

Validate the login cookie.

Check the following conditions:

  • a record exists for the user, the series, but a different token
    • assume a fraud case
    • remove the rememberable cookie and delete the session
  • a record exists for the user, the series, and the token
    • a valid remembered user
  • otherwise, this is an unknown user.