authority v0.3.0 Authority.Registration behaviour
A behaviour for registering and updating users.
The core callbacks are:
create_user/1
get_user/1
update_user/2
delete_user/1
Applications which have a concept of changesets, (such as Ecto.Changeset
for example) may find it useful to implement the optional callbacks as well:
change_user/0
change_user/1
change_user/2
Example
defmodule MyApp.Accounts.Registration do
use Authority.Registration
# OPTIONAL
@impl Authority.Registration
def change_user do
# Return a changeset for a new user
end
# OPTIONAL
@impl Authority.Registration
def change_user(user, params \ %{}) do
# Return a changeset for an existing user
end
# REQUIRED
@impl Authority.Registration
def create_user(params) do
# Create a user
end
# REQUIRED
@impl Authority.Registration
def get_user(id) do
# Get a user by ID
end
# REQUIRED
@impl Authority.Registration
def update_user(user, params) do
# Update the user
end
# REQUIRED
@impl Authority.Registration
def delete_user(user) do
# Delete the user
end
end
Link to this section Summary
Types
Any type that represents a changeset
An error returned from creating/updating/deleting a user
An identifier for the user, such as an integer ID used as its primary key in the database
Parameters needed to create a user. For example,
A user. Can be any type that represents a user for your application
Callbacks
OPTIONAL. Returns a changeset for a new user
OPTIONAL. Returns a changeset for a given user
OPTIONAL. Returns a changeset for a given user and params
Creates a user
Deletes a user
Gets a user by ID
Updates a user with the given parameters
Link to this section Types
Any type that represents a changeset.
An error returned from creating/updating/deleting a user.
An identifier for the user, such as an integer ID used as its primary key in the database.
Parameters needed to create a user. For example,
%{
email: "my@email.com",
password: "password",
password_confirmation: "password"
}
A user. Can be any type that represents a user for your application.
Link to this section Callbacks
OPTIONAL. Returns a changeset for a new user.
OPTIONAL. Returns a changeset for a given user.
OPTIONAL. Returns a changeset for a given user and params.
Creates a user.
Deletes a user.
Gets a user by ID.
Updates a user with the given parameters.