Haytni v0.6.1 Haytni.RegisterablePlugin View Source
This plugin allows the user to register and edit their account.
Change your_app/lib/your_app/user.ex to add two functions: create_registration_changeset
and update_registration_changeset
.
Example:
defmodule YourApp.User do
require YourApp.Haytni
@derive {Inspect, except: [:password]}
schema "users" do
YourApp.Haytni.fields()
# ...
end
# ...
# called when a user try to register himself
def create_registration_changeset(%__MODULE__{} = struct, params) do
struct
|> cast(params, ~W[email password]a) # add any field you'll may need (but only fields that user is allowed to define!)
|> YourApp.Haytni.validate_password()
# add any custom validation here
|> YourApp.Haytni.validate_create_registration()
end
# called when a user try to edit its own account (logic is completely different)
def update_registration_changeset(%__MODULE__{} = struct, params) do
struct
|> cast(params, ~W[email password current_password]a) # add any field you'll may need (but only fields that user is allowed to redefine!)
# add any custom validation here
|> YourApp.Haytni.validate_update_registration()
end
# ...
end
Fields: none
Configuration:
email_regexp
(default:~r/^[^@\s]+@[^@\s]+$/
): theRegex
that an email at registration or profile edition needs to matchcase_insensitive_keys
(default:~W[email]a
): list of fields to automatically downcase on registration. May be unneeded depending on your database (eg: citext columns for PostgreSQL or columns with a collation suffixed by "_ci" for MySQL). You SHOULD NOT include the password field here!strip_whitespace_keys
(default:~W[email]a
): list of fields to automatically strip from whitespaces. You SHOULD NEITHER include the password field here, to exclude any involuntary mistake, you should instead consider using a custom validation.email_index_name
(default:nil
, translated to<source>_email_index
byEcto.Changeset.unique_constraint/3
): the name of the unique index/constraint on email fieldregistration_disabled?
(default:false
): disable any new registration (existing users are still able to login, edit their profile, ...)stack Haytni.RegisterablePlugin, registration_disabled?: false, strip_whitespace_keys: ~W[email]a, case_insensitive_keys: ~W[email]a, email_regexp: ~r/^[^@\s]+@[^@\s]+$/, email_index_name: nil
Routes:
haytni_<scope>_registration_path
(actions: new/create, edit/update): paths used by the generated routes for this plugin can be customized on YourAppWeb.Haytni.routes/1 call in your router by the following options:- registration_path (default:
"/registration"
): the base/default path for all the actions - new_registration_path (default:
registration_path <> "/new"
): define this option to define a specific path for the new action (sign up/account creation) - edit_registration_path (default:
registration_path <> "/edit"
): same for edit action (profile edition)
- registration_path (default:
Link to this section Summary
Functions
Downcase values of a changeset to keys configured as case_insensitive_keys
Callback implementation for Haytni.Plugin.find_user/3
.
Callback implementation for Haytni.Plugin.invalid?/2
.
Callback implementation for Haytni.Plugin.on_email_change/4
.
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_logout/2
.
Callback implementation for Haytni.Plugin.on_registration/3
.
Callback implementation for Haytni.Plugin.on_successful_authentication/5
.
Trim values of a changeset to keys configured as strip_whitespace_keys
Callback implementation for Haytni.Plugin.validate_password/2
.
Link to this section Functions
Specs
case_insensitive_changes( changeset :: Ecto.Changeset.t(), config :: Haytni.RegisterablePlugin.Config.t() ) :: Ecto.Changeset.t()
Downcase values of a changeset to keys configured as case_insensitive_keys
Callback implementation for Haytni.Plugin.find_user/3
.
Callback implementation for Haytni.Plugin.invalid?/2
.
Callback implementation for Haytni.Plugin.on_email_change/4
.
Callback implementation for Haytni.Plugin.on_failed_authentication/5
.
Callback implementation for Haytni.Plugin.on_logout/2
.
Callback implementation for Haytni.Plugin.on_registration/3
.
Callback implementation for Haytni.Plugin.on_successful_authentication/5
.
Specs
strip_whitespace_changes( changeset :: Ecto.Changeset.t(), config :: Haytni.RegisterablePlugin.Config.t() ) :: Ecto.Changeset.t()
Trim values of a changeset to keys configured as strip_whitespace_keys
Callback implementation for Haytni.Plugin.validate_password/2
.