Pow v1.0.1 Pow.Ecto.Schema behaviour View Source

Handles the Ecto schema for user.

The macro will create a :pow_fields module attribute, and append fields to it. The pow_user_fields/0 macro will use these attributes to create fields in the ecto schema.

A default changeset/2 method is created, but can be overridden with a custom changeset/2 method.

Usage

Configure lib/my_project/users/user.ex the following way:

defmodule MyApp.Users.User do
  use Ecto.Schema
  use Pow.Ecto.Schema,
    user_id_field: :email,
    password_hash_methods: {&Pow.Ecto.Schema.Password.pbkdf2_hash/1,
                            &Pow.Ecto.Schema.Password.pbkdf2_verify/2},
    password_min_length: 10,
    password_max_length: 4096

  schema "users" do
    field :custom_field, :string

    pow_user_fields()

    timestamps()
  end

  def changeset(user_or_changeset, attrs) do
    pow_changeset(user, attrs)
  end
end

Remember to add user: MyApp.Users.User to your configuration.

Customize Pow fields

Pow fields can be overridden if the field name and type matches:

defmodule MyApp.Users.User do
  use Ecto.Schema
  use Pow.Ecto.Schema

  schema "users" do
    field :encrypted_password, :string
    field :password_hash, :string, source: :encrypted_password

    pow_user_fields()

    timestamps()
  end
end

Configuration options

  • :user_id_field - the field to use for user id. This value defaults to :email, and the changeset will automatically validate it as an e-mail.

Link to this section Summary

Functions

Filters field-type pairs that doesn't already exist in schema

Normalizes the user id field

A macro to add fields from the @pow_fields module attribute generated in __using__/1

Get user id field key from configuration

Link to this section Functions

Link to this function

filter_new_fields(fields, existing_fields) View Source
filter_new_fields([tuple()], [tuple()]) :: [tuple()]

Filters field-type pairs that doesn't already exist in schema.

Link to this function

normalize_user_id_field_value(value) View Source
normalize_user_id_field_value(binary()) :: binary()

Normalizes the user id field.

Keeps the user id field value case insensitive and removes leading and trailing whitespace.

Link to this macro

pow_user_fields() View Source (macro)

A macro to add fields from the @pow_fields module attribute generated in __using__/1.

Link to this function

user_id_field(config \\ []) View Source
user_id_field(Pow.Config.t()) :: atom()

Get user id field key from configuration.

Defaults to :email.

Link to this section Callbacks

Link to this callback

verify_password(arg0, binary) View Source
verify_password(Ecto.Schema.t(), binary()) :: boolean()