Haytni v0.6.1 Haytni 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.
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.
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
Get the list of shared (templates/views) or independant (Haytni stack) files to install
Update user's registration, its own registration.
Update the given user from a list of changes as Keyword
.
Same as update_user_with/2
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 validate_password/2
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/2
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
user() :: struct()
Link to this section Functions
Specs
authentication_failed(module :: module(), user :: user() | nil) :: {:ok, %{required(Ecto.Multi.name()) => any()}} | {:error, Ecto.Multi.name(), any(), %{required(Ecto.Multi.name()) => any()}}
Notifies plugins that the authentication failed for user.
If user is nil
, nothing is done.
Specs
change_user( user_or_module :: module() | user(), params :: %{optional(String.t()) => String.t()} ) :: 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()) :: {:ok, %{required(Ecto.Multi.name()) => any()}} | {:error, Ecto.Multi.name(), any(), %{required(Ecto.Multi.name()) => any()}}
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/3
for options.
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
login(conn :: Plug.Conn.t(), module :: module(), user :: user()) :: {: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
update_registration( module :: module(), user :: user(), attrs :: map(), options :: Keyword.t() ) :: {:ok, %{required(Ecto.Multi.name()) => any()}} | {:error, Ecto.Multi.name(), any(), %{required(Ecto.Multi.name()) => any()}}
Update user's registration, its own registration.
Works exactly as create_user
. The only difference is the additionnal parameter: the user to update as first one.
NOTE: the callbacks of Ecto.Multi.run
added to the multi by the on_email_change/4
callback will receive from the
Map
they get as their (single) argument the following predefined elements:
- the updated user as the
:user
key - the previous email as
:old_email
:new_email
: the new email
Specs
update_user_with(module :: module(), user :: user(), changes :: Keyword.t()) :: {:ok, user()} | {:error, Ecto.Changeset.t()}
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/2
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 validate_password/2
callback) of the module Haytni
stack. An %Ecto.Changeset{}
is returned with the potential validation errors added by the plugins.
Do NOT call it from your function validate_update_registration/2
, it will be called internally only if needed.
Specs
validate_update_registration( module :: module(), changeset :: Ecto.Changeset.t() ) :: Ecto.Changeset.t()
Same than validate_update_registration/2
but at registration's edition.