Openmaize v1.0.0-beta.5 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.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

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

check_time(arg0, atom)

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.

find_user(arg0, atom)

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.

find_user_byid(arg0)

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.

password_reset(struct, arg1)

Specs

password_reset(struct, String.t) ::
  {:ok, struct} |
  {:error, String.t}

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}.

user_confirmed(struct)

Specs

user_confirmed(struct) ::
  {:ok, struct} |
  {:error, struct}

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)}.