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 and email_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

Link to this function

allow_silent_password_recovery_for_unknown_user(opts \\ false)

Link to this function

allow_unconfirmed_access_for(opts \\ 0)

Link to this function

assigns_key(opts \\ :current_user)

Link to this function

async_rememberable?(opts \\ false)

Link to this function

auth_module(opts \\ Coherence.Authentication.Session)

Link to this function

changeset(opts \\ nil)

Link to this function

confirm_email_updates(opts \\ false)

Link to this function

confirmation_token_expire_days(opts \\ 5)

Link to this function

create_login(opts \\ :create_login)

Link to this function

credential_store(opts \\ nil)

Link to this function

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",
})
Link to this function

delete_login(opts \\ :delete_login)

@spec email_from() :: {nil, nil} | {String.t(), String.t()} | String.t()

Get the email_from configuration

Link to this function

email_from_email(opts \\ nil)

Link to this function

email_from_name(opts \\ nil)

Link to this function

email_reply_to()

@spec email_reply_to() :: nil | true | {String.t(), String.t()} | String.t()

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
Link to this function

email_reply_to_email(opts \\ nil)

Link to this function

email_reply_to_name(opts \\ nil)

Link to this function

forwarded_invitation_fields(opts \\ [:email, :name])

Link to this function

get(key, default \\ nil)

@spec get(atom(), any()) :: any()

Get a configuration item.

Link to this function

has_action?(option, action)

@spec has_action?(atom(), atom()) :: boolean()

Test if an option is configured and accepts a specific action

Link to this function

has_option(option)

@spec has_option(atom()) :: boolean()

Test if an options is configured.

Link to this function

invitation_permitted_attributes(opts \\ nil)

Link to this function

layout(opts \\ nil)

Link to this function

log_emails(opts \\ nil)

Link to this function

logged_in_url(opts \\ nil)

Link to this function

logged_out_url(opts \\ nil)

Link to this function

login_cookie(opts \\ "coherence_login")

Link to this function

login_field(opts \\ :email)

Get the configured mailer adapter

Link to this function

max_failed_login_attempts(opts \\ 5)

Link to this function

messages_backend(opts \\ nil)

Link to this function

minimum_password_length(opts \\ 4)

Link to this function

module(opts \\ nil)

Link to this function

opts(opts \\ [])

Link to this macro

password_hash()

(macro)

Macro to fetch the password_hash field.

Use a macro here to optimize performance.

Link to this function

password_hash_field(opts \\ :password_hash)

Link to this function

password_hashing_alg(opts \\ Comeonin.Bcrypt)

Link to this function

password_reset_permitted_attributes(opts \\ nil)

Link to this function

registration_permitted_attributes(opts \\ nil)

Link to this function

repo(opts \\ nil)

Link to this function

require_current_password(opts \\ true)

Link to this function

reset_token_expire_days(opts \\ 2)

Link to this function

router(opts \\ nil)

Link to this function

schema_key(opts \\ nil)

Link to this function

session_key(opts \\ "session_auth")

Link to this function

session_permitted_attributes(opts \\ nil)

Link to this function

site_name(opts \\ nil)

@spec title() :: String.t() | nil

Get title

Link to this function

token_assigns_key(opts \\ :user_token)

Link to this function

token_generator(opts \\ &Coherence.SessionService.sign_user_token/2)

Link to this function

token_max_age(opts \\ 1_209_600)

Link to this function

token_salt(opts \\ "user socket")

Link to this function

unlock_timeout_minutes(opts \\ 20)

Link to this function

unlock_token_expire_minutes(opts \\ 5)

Link to this function

update_login(opts \\ :update_login)

Link to this function

use_binary_id(opts \\ nil)

Link to this function

use_binary_id?()

@spec use_binary_id?() :: boolean()

Test if Phoenix is configured to use binary ids by default

Link to this function

user_active_field(opts \\ nil)

Link to this function

user_schema(opts \\ nil)

Link to this function

user_token(opts \\ nil)

Link to this function

verify_user_token(opts \\ &Coherence.SessionService.verify_user_token/2)

Link to this function

web_module(opts \\ nil)