Haytni (Haytni v0.7.0) View Source
Documentation for Haytni.
Link to this section Summary
Functions
Notifies plugins that the authentication failed for user.
Creates an %Ecto.Changeset{}
for a new user/account (at registration from a module)
or from a user (when editing account from a struct)
Register user from controller's params.
To delete user.
Function to be called, for the user, to modify its own email address: it actually updates it in the database but also
invokes, first, the Haytni.Plugin.on_email_change/4
callback of the plugins registered in the module Haytni stack.
Extracts an Haytni stack (module) from a Plug connection
Injects Ecto.Schema.field
s necessary to enabled plugins into your User schema
Used by plug to extract the current user (if any) from the HTTP request (meaning from headers, cookies, etc)
Fetchs a user from its id.
Fetches a user from the Ecto.Repo specified in config :haytni, YourApp.Haytni
as repo
subkey via the
attributes specified by clauses as a map or a keyword-list.
Checks if a user is valid according to plugins.
To be called on (manual) login
Notifies plugins that current user is going to be logged out
Returns true
if plugin is enabled in the module Haytni stack.
Injects the necessary routes for enabled plugins into your Router
Returns the name of the assign (in Plug.Conn and templates) of the current user
Returns the name of the session key which carries the user
Get the list of shared (templates/views) or independant (Haytni stack) files to install
Update user's registration, its own registration.
Update user in the same way as update_user_with/3
but as part of a set of operations (Ecto.Multi).
Update the given user from a list of changes as Keyword
.
Same as update_user_with/3
but returns the updated user struct or raises if changes are invalid.
This function is a callback to be called from your User.create_registration_changeset/2
so validations
and others internal tasks can be done by plugins at user's registration.
Runs any custom password validations from the plugins (via their Haytni.Plugin.validate_password/3
callback) of
the module Haytni stack. An %Ecto.Changeset{}
is returned with the potential validation errors added by the plugins.
Same than validate_update_registration/3
but at registration's edition.
Link to this section Types
Specs
config() :: any()
Specs
duration() :: pos_integer() | {pos_integer(), duration_unit()}
Specs
duration_unit() :: :second | :minute | :hour | :day | :week | :month | :year
Specs
irrelevant() :: any()
Specs
multi_result() :: {:ok, %{required(Ecto.Multi.name()) => any()}} | {:error, Ecto.Multi.name(), any(), %{optional(Ecto.Multi.name()) => any()}}
Specs
nilable(type) :: type | nil
Specs
Specs
repo_nobang_operation(type) :: {:ok, type} | {:error, Ecto.Changeset.t()}
Specs
user() :: struct()
Link to this section Functions
Specs
authentication_failed(module :: module(), user :: nilable(user())) :: multi_result()
Notifies plugins that the authentication failed for user.
If user is nil
, nothing is done.
Specs
change_user(user_or_module :: module() | user(), params :: params()) :: Ecto.Changeset.t()
Creates an %Ecto.Changeset{}
for a new user/account (at registration from a module)
or from a user (when editing account from a struct)
Specs
create_user(module :: module(), attrs :: map(), options :: Keyword.t()) :: multi_result()
Register user from controller's params.
Returned value is one of:
{:ok, map}
where map is the result of the internalsEcto.Multi.*
calls{:error, failed_operation, result_of_failed_operation, changes_so_far}
with:- failed_operation: the name of the operation which failed
- result_of_failed_operation: its result/returned value
- changes_so_far: same as map of the
{:ok, map}
case
The inserted user will be part of map (or eventualy changes_so_far) under the key :user
.
See Ecto.Repo.insert/2
for options.
Specs
delete_user(module :: module(), user :: user()) :: multi_result()
To delete user.
This function doesn't actually do nothing except calling the Haytni.Plugin.on_delete_user/4
callbacks
from the plugins in the Haytni's module stack. This way you can implement it the way you like and do
extra stuffs like deleting files associated to user.
See documentation of Haytni.Plugin.on_delete_user/4
for some examples.
Specs
email_changed( module :: module(), user :: user(), new_email_address :: String.t() ) :: multi_result()
Function to be called, for the user, to modify its own email address: it actually updates it in the database but also
invokes, first, the Haytni.Plugin.on_email_change/4
callback of the plugins registered in the module Haytni stack.
Note: caller is responsible for validations against new_email_address
Specs
fetch_module_from_conn!(conn :: Plug.Conn.t()) :: module()
Extracts an Haytni stack (module) from a Plug connection
Raises if no Haytni's stack was defined (through the router).
Injects Ecto.Schema.field
s necessary to enabled plugins into your User schema
Note that this function is invoked at compile time: you'll need to recompile your application to reflect any change related to fields injected in your user schema.
Specs
find_user(module :: module(), conn :: Plug.Conn.t()) :: {Plug.Conn.t(), user() | nil}
Used by plug to extract the current user (if any) from the HTTP request (meaning from headers, cookies, etc)
Specs
Fetchs a user from its id.
Returns nil
if no user matches.
Example:
case Haytni.get_user_by(YourApp.Haytni, params["id"]) do
nil ->
# not found
user = %User{} ->
# do something of user
end
Specs
Fetches a user from the Ecto.Repo specified in config :haytni, YourApp.Haytni
as repo
subkey via the
attributes specified by clauses as a map or a keyword-list.
Returns nil
if no user matches.
Example:
hulk = Haytni.get_user_by(YourApp.Haytni, first_name: "Robert", last_name: "Banner")
Specs
Checks if a user is valid according to plugins.
Returns false
if the user is valid else {:error, reason}
.
Specs
login( conn :: Plug.Conn.t(), module :: module(), user :: user(), changes :: Keyword.t() ) :: {:ok, Plug.Conn.t()} | {:error, String.t()}
To be called on (manual) login
Specs
logout(conn :: Plug.Conn.t(), module :: module(), options :: Keyword.t()) :: Plug.Conn.t()
Notifies plugins that current user is going to be logged out
Specs
Returns true
if plugin is enabled in the module Haytni stack.
Injects the necessary routes for enabled plugins into your Router
Note that this function is invoked at compile time: you'll need to recompile your application to reflect any change in your router.
Specs
Returns the name of the assign (in Plug.Conn and templates) of the current user
Specs
Returns the name of the session key which carries the user
Specs
update_registration( module :: module(), user :: user(), attrs :: map(), options :: Keyword.t() ) :: repo_nobang_operation(user())
Update user's registration, its own registration.
Specs
update_user_in_multi_with( multi :: Ecto.Multi.t(), name :: Ecto.Multi.name(), user :: user(), changes :: Keyword.t() ) :: Ecto.Multi.t()
Update user in the same way as update_user_with/3
but as part of a set of operations (Ecto.Multi).
Specs
update_user_with(module :: module(), user :: user(), changes :: Keyword.t()) :: repo_nobang_operation(user())
Update the given user from a list of changes as Keyword
.
Returns {:error, changeset}
if there was a validation or a known constraint error else {:ok, struct}
where struct is the updated user.
NOTE: for internal use, there isn't any validation. Do NOT inject values from controller's params!
Specs
update_user_with!(module :: module(), user :: user(), changes :: Keyword.t()) :: user() | no_return()
Same as update_user_with/3
but returns the updated user struct or raises if changes are invalid.
Specs
validate_create_registration( module :: module(), changeset :: Ecto.Changeset.t() ) :: Ecto.Changeset.t()
This function is a callback to be called from your User.create_registration_changeset/2
so validations
and others internal tasks can be done by plugins at user's registration.
Specs
validate_password(module :: module(), changeset :: Ecto.Changeset.t()) :: Ecto.Changeset.t()
Runs any custom password validations from the plugins (via their Haytni.Plugin.validate_password/3
callback) of
the module Haytni stack. An %Ecto.Changeset{}
is returned with the potential validation errors added by the plugins.
Specs
validate_update_registration( module :: module(), changeset :: Ecto.Changeset.t() ) :: Ecto.Changeset.t()
Same than validate_update_registration/3
but at registration's edition.