TODO: Add description
Add your model specifications to config.
config :elegua, # These are the default values, but imagine a model like:
user_model: YourApp.User, # MyApp.Player
app_repo: YourApp.Repo, # MyApp.Repo
password_field: :password, # :passphrase
username_field: :username, # :user
email_field: :email, # :mail
# these two are only needed if you'd like to verify users' email
# and thi is the only field that must have this name
verification_token_field: :verification_token,
is_verified_field: :is_verified # :active
defmodule MyApp.Registration do
alias MyApp.MyUser
def create(params) do
changeset =
Elegua.changeset(%MyUser{}, params)
|> MyUser.another_changeset(params)
# And so on ad infinitum
if changeset.valid? do
{:ok, user} = Elegua.register(changeset)
# Other happy things
else
# Handle error
end
end
end
defmodule MyApp.Registration do
alias MyApp.MyUser
@from "no-reply@myawesomeapp.com"
@subject "Welcome to MyAwesomeApp!"
def create(params) do
changeset =
Elegua.changeset(%MyUser{}, params)
|> MyUser.another_changeset(params)
if changeset.valid? do
# Passing `verify` as an option
{:ok, user} = Elegua.register(changeset, :verify)
verification_token = changeset.params["verification_token"]
# You must add the token to the content
content = "Your verification token: #{verification_token}"
Elegua.send_verification_email(user_email, @from, @subject, {:text, content})
# OR you can send HTML
# content = "<h2>Welcome to Phoenix!</h2>"
# Elegua.send_verification_email(user_email, @from, @subject, {:html, content})
# IF you're using Phoenix, you can get your templates
# rendered to string with `Phoenix.View.render_to_string`
# https://hexdocs.pm/phoenix/Phoenix.View.html#render_to_string/3
else
# Handle error
end
end
def verify(token) do
Elegua.verify(token)
end
end
If available in Hex, the package can be installed as:
-
Add elegua to your list of dependencies in
mix.exs
:def deps do [{:elegua, "~> 0.0.1"}] end
-
Ensure elegua is started before your application:
def application do [applications: [:elegua]] end