Packages

Adds helpful extras to Guardian like default mailer support, as well as out of the box controllers and routes

Current section

Files

Jump to
sentinel lib sentinel confirm.ex
Raw

lib/sentinel/confirm.ex

defmodule Sentinel.Confirm do
@moduledoc """
Handles the common confirmation logic
"""
alias Sentinel.Changeset.Confirmator
alias Sentinel.Config
alias Sentinel.Mailer
def send_confirmation_instructions(%{"email" => email} = params) do
user = Config.repo.get_by(Config.user_model, email: email)
unless is_nil(user) do
{confirmation_token, changeset} =
params
|> Sentinel.Changeset.Registrator.changeset
|> Confirmator.confirmation_needed_changeset
Config.repo.insert(changeset)
user
|> Mailer.send_welcome_email(confirmation_token)
|> Mailer.managed_deliver
end
end
def send_confirmation_instructions(_params) do
end
def do_confirm(params = %{"id" => id}) do
Config.user_model
|> Config.repo.get(id)
|> Config.user_model.changeset(params)
|> Confirmator.confirmation_changeset
|> Config.repo.update
end
end