Openmaize.Config
This module provides an abstraction layer for configuration. The following are valid configuration items.
name | type | default |
---|---|---|
user_model | module | N/A |
repo | module | N/A |
crypto_mod | atom | :bcrypt |
login_dir | string | “/admin” |
redirect_pages | map | %{“admin” => “/admin”, nil => “/“} |
protected | list | %{“/admin” => ["admin"]} |
secret_key | string | “you will never guess” |
token_info | list | [:id, :name, :role] |
token_validity | integer | 24 * 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
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.
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 path is the start of the path. For example, “/users” refers to all paths that start with “/users”.
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.
The secret key for use with Joken (which encodes and decodes the tokens).
In production, the default key should be changed.
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.