Coherence v0.1.3 Coherence.ControllerHelpers

Common helper functions for Coherence Controllers.

Summary

Functions

Confirm a user account

Test if a datetime has expired

Log an error message when lockable update fails

Get the configured logged_out_url

Get a random string of given length

Get the MyProject.Router.Helpers module

Send confirmation email with token

Unlock a user account

Functions

confirm!(user)

Confirm a user account.

Adds the :confirmed_at datetime field on the user model and updates the database

expired?(datetime, opts)

Test if a datetime has expired.

Convert the datetime from Ecto.DateTime 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)
lock!(user, locked_at \\ Ecto.DateTime.utc())

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.

lockable_failure(changeset)

Log an error message when lockable update fails.

logged_out_url(conn)

Get the configured logged_out_url.

random_string(length)

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.

router_helpers()

Get the MyProject.Router.Helpers module.

Returns the projects Router.Helpers module.

send_confirmation(conn, user, user_schema)

Send confirmation email with token.

If the user supports confirmable, generate a token and send the email.

send_user_email(fun, model, url)

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.

unlock!(user)

Unlock a user account.

Clears the :locked_at field on the user model and updates the database.