Coherence.Config (Coherence v0.8.0)
Coherence Configuration Module.
Provides a small wrapper around Application.get_env :coherence
, providing an
accessor function for each configuration items.
Configuration items can be defined as either a single atom or {name, default}
tuple. Each of the items can be included in your config/config.exs
file.
The following items are supported:
- :allow_silent_password_recovery_for_unknown_user (false)
- :allow_unconfirmed_access_for (0) - default 0 days
- :assigns_key (:current_user)
- :async_rememberable? (false) - Don't update rememberable seq_no for ajax requests
- :auth_module (Coherence.Authentication.Session)
- :changeset - Custom user changeset
- :confirm_email_updates (false) - All email updates should be confirmed by email (using the unconfirmed_email field)
- :confirmation_token_expire_days (5)
- :create_login (:create_login)
- :credential_store - override the credential store module
- :delete_login (:delete_login)
- :email_from - Deprecated. Use
email_from_name
andemail_from_email
instead - :email_from_email
- :email_from_name
- :email_reply_to - Set to true to add email_from_name and email_from_email
- :email_reply_to_email
- :email_reply_to_name
- :invitation_permitted_attributes - List of allowed invitation parameter attribues as strings
- :layout - Customize the layout template e.g. {MyApp.LayoutView, "app.html"}
- :log_emails - Set to true to log each rendered email.
- :logged_in_url
- :logged_out_url
- :login_cookie ("coherence_login") - The name of the login cookie
- :login_field (:email) - The user model field used to login
- :max_failed_login_attempts (5)
- :messages_backend - (MyApp.Coherence.Messages)
- :minimum_password_length The minimum password length to be accepted. Default value is 4.
- :module - the name of project module (
module: MyProject
) - :opts ([])
- :password_hash_field (:password_hash) - The field used to save the hashed password
- :password_hashing_alg (Comeonin.Bcrypt) - Password hashing algorithm to use.
- :password_reset_permitted_attributes - List of allowed password reset atributes as stings,
- :registration_permitted_attributes - List of allowed registration parameter attributes as strings
- :repo: the module name of your Repo (
repo: MyProject.Repo
) - :rememberable_cookie_expire_hours (2*24)
- :reset_token_expire_days (2)
- :router: the module name of your Router (
router: MyProject.Router
) - :schema_key
- :session_key ("session_auth")
- :session_permitted_attributes - List of allowed session attributes as strings
- :site_name - The site name used for email
- :title - Layout page title
- :token_assigns_key (:user_token) - key used to access the channel_token in the conn.assigns map
- :token_generator (fn conn, user -> Phoenix.Token.sign(conn, "user socket", user.id) end) - override the default may also provide an arity 3 function as a tuple {Module, :function, args} where apply(Module, function, args) will be used
- :token_max_age (2 7 24 60 60) - Phoenix.Token max_age
- :token_salt ("user socket") - Phoenix.Token salt
- :update_login (:update_login)
- :unlock_timeout_minutes (20)
- :unlock_token_expire_minutes (5)
- :use_binary_id (false) - Use binary ids.
- :user_active_field - Include the user active feature
- :user_token (false) - generate tokens for channel authentication
- :user_schema
- :verify_user_token (fn socket, token -> Phoenix.Token.verify(socket, "user socket", token, max_age: 2 7 24 60 60) end can also be a 3 element tuple as described above for :token_generator
- :web_module - the name of the project's web module (
web_module: MyProjectWeb
)
Examples
alias Coherence.Config
Config.module
Summary
Functions
Get the configured routes.
Get the email_from configuration
Get the email_reply_to value.
Get a configuration item.
Test if an option is configured and accepts a specific action
Test if an options is configured.
Get the configured mailer adapter
Macro to fetch the password_hash field.
Get title
Test if Phoenix is configured to use binary ids by default
Functions
allow_silent_password_recovery_for_unknown_user(opts \\ false)
allow_unconfirmed_access_for(opts \\ 0)
assigns_key(opts \\ :current_user)
async_rememberable?(opts \\ false)
auth_module(opts \\ Coherence.Authentication.Session)
changeset(opts \\ nil)
confirm_email_updates(opts \\ false)
confirmation_token_expire_days(opts \\ 5)
create_login(opts \\ :create_login)
credential_store(opts \\ nil)
default_routes()
Get the configured routes.
If config[:default_routes] is nil, return the default routes, otherwise, return the the configured map.
Examples
iex Application.put_env(:coherence, :default_routes, %{
passwords: "/passwords",
sessions: "/sessions",
})
:ok
iex Coherence.Config.default_routes()
%{
passwords: "/passwords",
sessions: "/sessions",
})
delete_login(opts \\ :delete_login)
email_from()
Get the email_from configuration
email_from_email(opts \\ nil)
email_from_name(opts \\ nil)
email_reply_to()
Get the email_reply_to value.
Fetches :email_reply_to
from coherence configuration
- if nil, returns {config[:email_reply_to_name], config[:email_reply_to_email]}
- if true, returns true
- if email, returns email with a deprecation logged
email_reply_to_email(opts \\ nil)
email_reply_to_name(opts \\ nil)
forwarded_invitation_fields(opts \\ [:email, :name])
get(key, default \\ nil)
Get a configuration item.
has_action?(option, action)
Test if an option is configured and accepts a specific action
has_option(option)
Test if an options is configured.
invitation_permitted_attributes(opts \\ nil)
layout(opts \\ nil)
log_emails(opts \\ nil)
logged_in_url(opts \\ nil)
logged_out_url(opts \\ nil)
login_cookie(opts \\ "coherence_login")
login_field(opts \\ :email)
mailer?()
Get the configured mailer adapter
max_failed_login_attempts(opts \\ 5)
messages_backend(opts \\ nil)
minimum_password_length(opts \\ 4)
module(opts \\ nil)
opts(opts \\ [])
Macro to fetch the password_hash field.
Use a macro here to optimize performance.
password_hash_field(opts \\ :password_hash)
password_hashing_alg(opts \\ Comeonin.Bcrypt)
password_reset_permitted_attributes(opts \\ nil)
registration_permitted_attributes(opts \\ nil)
rememberable_cookie_expire_hours(opts \\ 48)
repo(opts \\ nil)
require_current_password(opts \\ true)
reset_token_expire_days(opts \\ 2)
router(opts \\ nil)
schema_key(opts \\ nil)
session_key(opts \\ "session_auth")
session_permitted_attributes(opts \\ nil)
site_name(opts \\ nil)
title()
@spec title() :: String.t() | nil
Get title
token_assigns_key(opts \\ :user_token)
token_generator(opts \\ &Coherence.SessionService.sign_user_token/2)
token_max_age(opts \\ 1_209_600)
token_salt(opts \\ "user socket")
unlock_timeout_minutes(opts \\ 20)
unlock_token_expire_minutes(opts \\ 5)
update_login(opts \\ :update_login)
use_binary_id(opts \\ nil)
use_binary_id?()
@spec use_binary_id?() :: boolean()
Test if Phoenix is configured to use binary ids by default