Openmaize v3.0.1 Openmaize.Database

Functions that are used to access the database.

Summary

Functions

Add a confirmation token to the user model or changeset

Hash the password and add it to the user model or changeset

Add a reset token to the user model or changeset

Function used to check if a token has expired

Get user and lock the database

Add the password hash for the new password to the database

Update the database with the new value for otp_last

Change the ‘confirmed_at’ value in the database to the current time

Functions

add_confirm_token(user, key)

Add a confirmation token to the user model or changeset.

Add the following three entries to your user schema:

field :confirmation_token, :string
field :confirmation_sent_at, Ecto.DateTime
field :confirmed_at, Ecto.DateTime

Examples

In the following example, the ‘add_confirm_token’ function is called with a key generated by ‘Openmaize.ConfirmEmail.gen_token_link’:

changeset |> Openmaize.Database.add_confirm_token(key)
add_password_hash(user, params)

Hash the password and add it to the user model or changeset.

Before the password is hashed, it is checked to make sure that it is not too weak. See the documentation for the Openmaize.Password module for more information about the options available.

This function will return a changeset. If there are any errors, they will be added to the changeset.

Comeonin.Bcrypt is the default hashing function, but this can be changed to Comeonin.Pbkdf2, or any other algorithm, by setting the Config.crypto_mod value.

add_reset_token(user, key)

Add a reset token to the user model or changeset.

Add the following two entries to your user schema:

field :reset_token, :string
field :reset_sent_at, Ecto.DateTime

As with ‘add_confirm_token’, the function ‘Openmaize.ConfirmEmail.gen_token_link’ can be used to generate the token and link.

check_time(sent_at, valid_secs)

Function used to check if a token has expired.

get_user_with_lock(repo, user_model, id)

Get user and lock the database.

This is used when updating the HOTP token.

password_reset(user, password, repo)

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.

update_otp(arg1, repo)

Update the database with the new value for otp_last.

This is used with both HOTP and TOTP tokens.

user_confirmed(user, repo)

Change the ‘confirmed_at’ value in the database to the current time.