View Source PowEmailConfirmation.Ecto.Schema (Pow v1.0.36)

Handles the e-mail confirmation schema for user.

Customize PowEmailConfirmation fields

If you need to modify any of the fields that PowEmailConfirmation adds to the user schema, you can override them by defining them before pow_user_fields/0:

defmodule MyApp.Users.User do
  use Ecto.Schema
  use Pow.Ecto.Schema
  use Pow.Extension.Ecto.Schema,
    extensions: [PowEmailConfirmation]

  schema "users" do
    field :email_confirmation_token, :string
    field :email_confirmed_at, :utc_datetime
    field :unconfirmed_email, :string

    pow_user_fields()

    timestamps()
  end
end

Summary

Functions

Handles e-mail confirmation if e-mail is updated.

Sets the e-mail as confirmed.

Functions

Link to this function

changeset(changeset, attrs, config)

View Source
@spec changeset(Ecto.Changeset.t(), map(), Pow.Config.t()) :: Ecto.Changeset.t()

Handles e-mail confirmation if e-mail is updated.

The :email_confirmation_token will always be set if the struct isn't persisted to the database.

For structs persisted to the database, no changes will happen if there is no :email in the params. Likewise, no changes will happen if the :email change is the same as the persisted :unconfirmed_email value.

If the :email change is the same as the persisted :email value then both :email_confirmation_token and :unconfirmed_email will be set to nil.

Otherwise the :email change will be copied over to :unconfirmed_email and the :email change will be reverted back to the original persisted :email value. A unique :email_confirmation_token will be generated.

Link to this function

confirm_email_changeset(changeset, params)

View Source
@spec confirm_email_changeset(Ecto.Schema.t() | Ecto.Changeset.t(), map()) ::
  Ecto.Changeset.t()

Sets the e-mail as confirmed.

This updates :email_confirmed_at and sets :email_confirmation_token to nil.

If the struct has a :unconfirmed_email value, then the :email will be changed to this value, and :unconfirmed_email will be set to nil.