Haytni.InvitablePlugin (Haytni v0.7.0) View Source

This plugin provides the feature of registration on invitation or sponsorship.

Fields: none

Configuration:

  • invitation_quota (default: :infinity): the maximum amount of invitation a user can send. Possible values:

    • :infinity if illimited
    • {count, :total}, count being a number, to restrict the user to a total of count invitation
    • {count, :unaccepted}, count being a number, to limit the user to count pending invitation
  • email_matching_invitation (default: false): true to force users who accept the invitation to register with the same email address they received the invitation from

  • invitation_required (default: true): true if users can only register with a valid invitation. false to make it optional (sponsorship).

  • invitation_within (default: {30, :day}): laps of time before the invitation can no longer be used (expiration)

  • invitation_sent_to_index_name (default: nil): the name of the index on sent_to column if you have to explicit it

    stack Haytni.InvitablePlugin,
      invitation_required: true,
      invitation_quota: :infinity,
      invitation_within: {30, :day},
      email_matching_invitation: false,
      invitation_sent_to_index_name: nil

Routes:

  • haytni_<scope>_invitation_path (actions: new/create): default path is "/invitations" but you can customize it to whatever you want by specifying the option :invitation_path to your YourApp.Haytni.routes/1 call in your router (eg: YourApp.Haytni.routes(invitation_path: "/sponsorship"))

Link to this section Summary

Functions

Build an invitation associated to user.

The translated string set as error when invitation token does not exist

The translated string set as error when email address does not match the invitation

The translated string set as error when invitation has expired

The translated string set as error when invitation quota is exceeded

The translated string set as error when invitation are required but any was provided

Converts an invitation to an Ecto.Changeset by applying the changes from params

Generates a length long random code

Resend (email) an invitation

Sends an invitation (by email) from user after checking if its quota (invitation_quota) allows it to

Link to this section Types

Specs

invitation() :: struct()

Link to this section Functions

Link to this function

build_and_assoc_invitation(user, attrs \\ %{})

View Source

Specs

build_and_assoc_invitation(user :: Haytni.user(), attrs :: Keyword.t() | map()) ::
  invitation()

Build an invitation associated to user.

Valid attributes (keys) for attrs are:

  • :code (required): the unique token associated to the invitation
  • :sent_at (required): when (DateTime) the invitation was sent
  • :sent_to (required): the email address the invitation was sent to
  • :accepted_by (for testing purpose only): the id of the user who accepted the invitation
  • :accepted_at (for testing purpose only): when (DateTime) the invitation was accepted
  • :id (for testing purpose only): force a (not nil) id for an in-memory (not persisted to database) invitation
Link to this function

find_user(conn, module, config)

View Source

Callback implementation for Haytni.Plugin.find_user/3.

Link to this function

invalid?(user, module, config)

View Source

Callback implementation for Haytni.Plugin.invalid?/3.

Link to this function

invalid_invitation_message()

View Source

Specs

invalid_invitation_message() :: String.t()

The translated string set as error when invitation token does not exist

Link to this function

invitation_email_mismatch_message()

View Source

Specs

invitation_email_mismatch_message() :: String.t()

The translated string set as error when email address does not match the invitation

Link to this function

invitation_expired_message()

View Source

Specs

invitation_expired_message() :: String.t()

The translated string set as error when invitation has expired

Link to this function

invitation_quota_exceeded_message(count)

View Source

Specs

invitation_quota_exceeded_message(count :: pos_integer()) :: String.t()

The translated string set as error when invitation quota is exceeded

Link to this function

invitation_required_message()

View Source

Specs

invitation_required_message() :: String.t()

The translated string set as error when invitation are required but any was provided

Link to this function

invitation_to_changeset(invitation, config, params \\ %{})

View Source

Specs

invitation_to_changeset(
  invitation :: invitation(),
  config :: Haytni.InvitablePlugin.Config.t(),
  params :: Haytni.params()
) :: Ecto.Changeset.t()

Converts an invitation to an Ecto.Changeset by applying the changes from params

Link to this function

on_delete_user(multi, user, module, config)

View Source

Callback implementation for Haytni.Plugin.on_delete_user/4.

Link to this function

on_email_change(multi, changeset, module, config)

View Source

Callback implementation for Haytni.Plugin.on_email_change/4.

Link to this function

on_failed_authentication(user, multi, keywords, module, config)

View Source

Callback implementation for Haytni.Plugin.on_failed_authentication/5.

Link to this function

on_logout(conn, module, config)

View Source

Callback implementation for Haytni.Plugin.on_logout/3.

Link to this function

on_successful_authentication(conn, user, multi, keywords, module, config)

View Source

Callback implementation for Haytni.Plugin.on_successful_authentication/6.

Generates a length long random code

Link to this function

resend_information(module, config, invitation)

View Source

Specs

resend_information(
  module :: module(),
  config :: Haytni.InvitablePlugin.Config.t(),
  invitation :: invitation()
) :: {:ok, true}

Resend (email) an invitation

Note: there is no checking and invitation.sender must have been preloaded

Link to this function

send_invitation(module, config, invitation_params, user)

View Source

Specs

send_invitation(
  module :: module(),
  config :: Haytni.InvitablePlugin.Config.t(),
  invitation_params :: Haytni.params(),
  user :: Haytni.user()
) :: Haytni.repo_nobang_operation(invitation())

Sends an invitation (by email) from user after checking if its quota (invitation_quota) allows it to

Link to this function

validate_password(changeset, module, config)

View Source

Callback implementation for Haytni.Plugin.validate_password/3.

Link to this function

validate_update_registration(changeset, module, config)

View Source

Callback implementation for Haytni.Plugin.validate_update_registration/3.