Openmaize.LoginoutCheck

Plug to check if the path is for the login or logout page and handles the login or logout if necessary. If the path is different, the connection is returned without any further checks being performed.

If the path ends with login and it is a GET request, the current_user is set to nil and the user is sent straight to the login page. If the path ends with login and it is a POST request, Openmaize processes the login request and then, if successful, sends a token back to the user, either stored in a cookie or sent in the response body. If redirects is set to true, the user is redirected to the user’s role’s page.

If the path ends with logout and the token is stored in a cookie, then the cookie is deleted. If redirects is set to true, the user is then redirected to the home page.

There are three options:

  • redirects

    • if true, which is the default, redirect on login / logout
  • storage

    • storage method for the token — the default is :cookie
    • if redirects is set to false, storage is automatically set to nil
  • token_validity

    • length of validity of token (in minutes) — the default is 1440 minutes (one day)

Examples

Call LoginoutCheck without any options:

plug Openmaize.LoginoutCheck

Call LoginoutCheck and send the token in the response body:

plug Openmaize.LoginoutCheck, storage: nil

Call LoginoutCheck without redirects:

plug Openmaize.LoginoutCheck, redirects: false

Call LoginoutCheck and set the token validity to two hours:

plug Openmaize.LoginoutCheck, token_validity: 120

Summary

Functions

Check the path and handle login or logout if necessary. If the path is not for the login or logout page, the connection is returned

Callback implementation for c:Plug.init/1

Functions

call(conn, opts)

Check the path and handle login or logout if necessary. If the path is not for the login or logout page, the connection is returned.

init(opts)

Callback implementation for c:Plug.init/1.