Openmaize.Config

This module provides an abstraction layer for configuration. The following are valid configuration items.

nametypedefault
user_modelmoduleN/A
repomoduleN/A
crypto_modatom:bcrypt
login_dirstring“/admin”
redirect_pagesmap%{“admin” => “/admin”, nil => “/“}
protectedlist%{“/admin” => ["admin"]}
secret_keystring“you will never guess”
token_infolist[:id, :name, :role]
token_validityinteger24 * 60

The values for user_model and repo should be module names. If, for example, your app is called Coolapp and your user model is called User, then user_model should be Coolapp.User and repo should be Coolapp.Repo.

Examples

The simplest way to change the default values would be to add the following to the config.exs file in your project.

config :openmaize,
  user_model: Coolapp.User,
  repo: Coolapp.Repo,
  crypto_mod: :bcrypt,
  login_dir: "admin",
  redirect_pages: %{"admin" => "/admin", "user" => "/users", nil => "/"},
  protected: %{"/admin" => ["admin"], "/users" => ["admin", "user"], "/users/:id" => ["user"]}
  secret_key: "so hard to guess",
  token_info: [:email, :shoesize],
  token_validity: 7 * 24 * 60

Summary

Functions

The password hashing and checking algorithm. You can choose between bcrypt and pbkdf2_sha512. Bcrypt is the default

The login directory. For example, the default value of “/admin” means that the login page is “/admin/login”

Paths that should be protected. This is a map associating each path with a role

The pages users should be redirected to after logging in. This is a map where the key is the role of the user and the value is the page to be redirected to

The repo name

The secret key for use with Joken (which encodes and decodes the tokens)

Additional information that can be added to the token. By default, the token will have an id, name and role

The number of minutes that you want the token to be valid for

The user model name

Functions

get_crypto_mod()

The password hashing and checking algorithm. You can choose between bcrypt and pbkdf2_sha512. Bcrypt is the default.

For more information about these two algorithms, see the documentation for Comeonin.

login_dir()

The login directory. For example, the default value of “/admin” means that the login page is “/admin/login”.

protected()

Paths that should be protected. This is a map associating each path with a role.

The path is the start of the path. For example, “/users” refers to all paths that start with “/users”.

redirect_pages()

The pages users should be redirected to after logging in. This is a map where the key is the role of the user and the value is the page to be redirected to.

If there is no role, the user will be redirected to the home page.

repo()

The repo name.

secret_key()

The secret key for use with Joken (which encodes and decodes the tokens).

In production, the default key should be changed.

token_info()

Additional information that can be added to the token. By default, the token will have an id, name and role.

This value takes a list of atoms.

token_validity()

The number of minutes that you want the token to be valid for.

user_model()

The user model name.