Packages
openmaize
1.0.0-beta.5
3.0.1
retired
3.0.0
2.9.0
2.8.0
2.7.0
2.6.0
2.5.1
2.5.0
2.4.0
2.3.2
2.3.1
2.3.0
2.2.0
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.2
2.0.1
2.0.0
1.0.1
1.0.0
1.0.0-beta.5
1.0.0-beta.4
1.0.0-beta.3
1.0.0-beta.2
1.0.0-beta.1
1.0.0-beta.0
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.17.2
0.17.1
0.17.0
0.16.2
0.16.1
0.16.0
0.15.1
0.15.0
0.14.0
0.13.0
0.12.0
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.8.1
0.8.0
0.7.5
0.7.4
0.7.2
0.7.1
0.7.0
0.6.7
0.6.6
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.1
0.4.0
Authentication library for Elixir using Plug
Current section
Files
Jump to
Current section
Files
lib/openmaize/database.ex
defmodule Openmaize.Database do
@moduledoc """
A behaviour which defines the functions that are called by other
Openmaize modules.
If you are using Ecto, you can generate a module that defines these
functions by running the following command:
mix openmaize.gen.ectodb
## Creating a custom module
If you are going to create a custom module, note that the following
functions are called by other modules in Openmaize:
* `find_user` - used in Openmaize.Login and Openmaize.ConfirmEmail
* `find_user_byid` - used in Openmaize.OnetimePass
* `user_confirmed` - used in Openmaize.ConfirmEmail
* `password_reset` - used in Openmaize.ResetPassword
* `check_time` - used in Openmaize.ConfirmEmail and Openmaize.ResetPassword
"""
@doc """
Query the database to find the current user based on a unique
identifier - username, email, or anything else.
The first argument is a string representing the user's username
or email (or something else). The second argument is an atom
which represents what the unique identifier, :username or
:email, etc., is.
This function returns a user struct.
"""
@callback find_user(String.t, atom) :: struct
@doc """
Query the database based on the user id.
The only argument is the user id.
This function returns a user struct.
"""
@callback find_user_byid(String.t | Integer) :: struct
@doc """
Update the database with the time when the email address was confirmed.
The only argument is the user struct.
This function returns a {:ok, user struct} or {:error, changeset (struct)}.
"""
@callback user_confirmed(struct) :: {:ok, struct} | {:error, struct}
@doc """
Add the password hash for the new password to the database.
If the update is successful, the reset_token and reset_sent_at
values will be set to nil.
The first argument is the user struct, and the second argument is
the password.
This function returns a {:ok, user struct} or {:error, error message}.
"""
@callback password_reset(struct, String.t) :: {:ok, struct} | {:error, String.t}
@doc """
Function used to check if a token has expired.
The first argument is the time when the token was created, and the second
argument is the number of seconds the token is valid for.
This function returns true or false.
"""
@callback check_time(Integer | nil, Integer) :: boolean
end