Pow v1.0.0-rc.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.
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
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
Normalizes the user id field.
Keeps the user id field value case insensitive.
A macro to add fields from the @pow_fields
module attribute generated in
__using__/1
.
user_id_field(Pow.Config.t()) :: atom()
Get user id field key from configuration.
Defaults to :email
.
Link to this section Callbacks
changeset(Ecto.Schema.t() | Ecto.Changeset.t(), map()) :: Ecto.Changeset.t()
verify_password(Ecto.Schema.t(), binary()) :: boolean()