Coherence v0.5.1 Coherence.Controller
Common helper functions for Coherence Controllers.
Link to this section Summary
Functions
Confirm a user account
Deactivate a user
Test if a datetime has expired
Put LayoutView
Lock a use account
Log an error message when lockable update fails
Get the configured logged_in_url
Get the configured logged_out_url
Login a user
Logout a user
leaves in params only permitted request parameters
Get a random string of given length
Plug to redirect already logged in users
Get the Router.Helpers module for the project
Send confirmation email with token
Sends an email if the mailer is properly configured and add the appropriate flash
Send a user email
Set view plug
Shift a NaiveDateTime
Unlock a user account
Link to this section Types
Link to this section Functions
Confirm a user account.
Adds the :confirmed_at
datetime field on the user model and updates the database
Deactivate a user.
Removes all logged in sessions for a user.
Test if a datetime has expired.
Convert the datetime from NaiveDateTime format to Timex format to do the comparison given the time during in opts.
Examples
expired?(user.expire_at, days: 5)
expired?(user.expire_at, minutes: 10)
iex> NaiveDateTime.utc_now()
...> |> Coherence.Controller.expired?(days: 1)
false
iex> NaiveDateTime.utc_now()
...> |> Coherence.Controller.shift(days: -2)
...> |> Coherence.Controller.expired?(days: 1)
true
layout_view(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Put LayoutView
Adds Config.layout if set.
lock!(Ecto.Schema.t(), struct()) :: schema_or_error()
Lock a use account.
Sets the :locked_at
field on the user model to the current date and time unless
provided a value for the optional parameter.
You can provide a date in the future to override the configured lock expiry time. You can set this data far in the future to do a pseudo permanent lock.
Log an error message when lockable update fails.
Get the configured logged_in_url.
Get the configured logged_out_url.
Login a user.
Logs in a user and redirects them to the session_create page.
Logout a user.
Logs out a user and redirects them to the session_delete page.
leaves in params only permitted request parameters.
Same as Rails permit, prevents mass assignment attacks.
Get a random string of given length.
Returns a random url safe encoded64 string of the given length. Used to generate tokens for the various modules that require unique tokens.
Plug to redirect already logged in users.
Get the Router.Helpers module for the project..
Returns the projects Router.Helpers module.
send_confirmation(Plug.Conn.t(), Ecto.Schema.t(), module()) :: Plug.Conn.t()
Send confirmation email with token.
If the user supports confirmable, generate a token and send the email.
Sends an email if the mailer is properly configured and add the appropriate flash.
send_user_email(atom(), Ecto.Schema.t(), String.t()) :: any()
Send a user email.
Sends a user email given the module, model, and url. Logs the email for debug purposes.
Note: This function uses an apply to avoid compile warnings if the mailer is not selected as an option.
Set view plug
Shift a NaiveDateTime.
Examples
iex> ~N(2016-10-10 10:10:10)
...> |> Coherence.Controller.shift(days: -2)
...> |> to_string
"2016-10-08 10:10:10Z"
Unlock a user account.
Clears the :locked_at
field on the user model and updates the database.