Haytni v0.0.1 Haytni View Source

Documentation for Haytni.

Link to this section Summary

Functions

Notifies plugins that the authentification failed for user

Register user from controller’s params

Convert a duration of the form {number, unit} to seconds

Injects Ecto.Schema.fields 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 or session)

To be called on (manual) login

Notifies plugins that current user is going to be logged out

Returns the mailer from application’s configuration

Helper for plugins to associate a mismatch error to fields given as keys of changeset

Returns the repo (implements Ecto.Repo) from application’s configuration

Injects the necessary routes for enabled plugins into your Router

Returns the user’s schema from application’s configuration

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

Same than validate_update_registration/2 but at registration’s edition

Link to this section Functions

Link to this function authentification_failed(user) View Source
authentification_failed(user :: struct() | nil) :: nil

Notifies plugins that the authentification failed for user.

If user is nil, nothing is done.

Link to this function create_user(attrs, options \\ []) View Source
create_user(attrs :: map(), options :: Keyword.t()) ::
  {:ok, %{optional(Ecto.Multi.name()) => any()}}
  | {:error, Ecto.Multi.name(), any(),
     %{optional(Ecto.Multi.name()) => any()}}

Register user from controller’s params.

Returned value is one of:

  • {:ok, map} where map is the result of the internals Ecto.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.

Convert a duration of the form {number, unit} to seconds.

unit can be one of the following:

  • :second
  • :minute
  • :hour
  • :day
  • :week
  • :month
  • :year
Link to this function fetch_config(key, default \\ nil) View Source

Injects Ecto.Schema.fields necessary to enabled plugins into your User schema

Link to this function find_user(conn) View Source
find_user(conn :: Plug.Conn.t()) :: {Plug.Conn.t(), struct() | nil}

Used by plug to extract the current user (if any) from the HTTP request (meaning from headers, cookies or session)

Link to this function layout(default \\ false) View Source
Link to this function login(conn, user) View Source
login(conn :: Plug.Conn.t(), user :: struct()) ::
  {:ok, Plug.Conn.t()} | {:error, String.t()}

To be called on (manual) login

Notifies plugins that current user is going to be logged out

Returns the mailer from application’s configuration

config :your_app, :haytni,
  mailer: YourApp.Mailer
Link to this function mark_changeset_keys_as_unmatched(changeset, keys) View Source
mark_changeset_keys_as_unmatched(
  changeset :: Ecto.Changeset.t(),
  keys :: [atom()]
) :: Ecto.Changeset.t()

Helper for plugins to associate a mismatch error to fields given as keys of changeset.

Returns an Ecto.Changeset.t with proper errors set.

Link to this function plugin_enabled?(module) View Source
plugin_enabled?(module :: module()) :: boolean()
Link to this function plugins(default \\ [Haytni.AuthenticablePlugin, Haytni.RegisterablePlugin, Haytni.RememberablePlugin, Haytni.ConfirmablePlugin, Haytni.LockablePlugin, Haytni.RecoverablePlugin]) View Source

Returns the repo (implements Ecto.Repo) from application’s configuration

config :your_app, :haytni,
  schema: YourApp.Repo
Link to this macro routes(options \\ []) View Source (macro)

Injects the necessary routes for enabled plugins into your Router

Returns the user’s schema from application’s configuration

config :your_app, :haytni,
  schema: YourApp.User
Link to this function update_registration(user, attrs, options \\ []) View Source
update_registration(user :: struct(), attrs :: map(), options :: Keyword.t()) ::
  {:ok, %{optional(Ecto.Multi.name()) => any()}}
  | {:error, Ecto.Multi.name(), any(),
     %{optional(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/2 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
Link to this function update_user_with(user, changes) View Source
update_user_with(user :: struct(), changes :: Keyword.t()) ::
  {:ok, struct()} | {: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!

Link to this function update_user_with!(user, changes) View Source
update_user_with!(user :: struct(), changes :: Keyword.t()) ::
  struct() | no_return()

Same as update_user_with/2 but returns the updated user struct or raises if changes are invalid.

Link to this function validate_create_registration(changeset) View Source
validate_create_registration(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.

Link to this function validate_update_registration(changeset) View Source
validate_update_registration(changeset :: Ecto.Changeset.t()) ::
  Ecto.Changeset.t()

Same than validate_update_registration/2 but at registration’s edition.