Openmaize v1.0.1 Openmaize.Database behaviour
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.ConfirmEmailfind_user_byid
- used in Openmaize.OnetimePassuser_confirmed
- used in Openmaize.ConfirmEmailpassword_reset
- used in Openmaize.ResetPasswordcheck_time
- used in Openmaize.ConfirmEmail and Openmaize.ResetPassword
Summary
Callbacks
Function used to check if a token has expired
Query the database to find the current user based on a unique identifier - username, email, or anything else
Query the database based on the user id
Add the password hash for the new password to the database
Update the database with the time when the email address was confirmed
Callbacks
Specs
check_time(Integer | nil, Integer) :: boolean
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.
Specs
find_user(String.t, atom) :: struct
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.
Specs
find_user_byid(String.t | Integer) :: struct
Query the database based on the user id.
The only argument is the user id.
This function returns a user struct.
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}.