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 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)
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 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.
Get user and lock the database.
This is used when updating the HOTP token.
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 the database with the new value for otp_last.
This is used with both HOTP and TOTP tokens.