Packages
phauxth
0.15.0
2.5.1
retired
2.5.0
2.4.0
2.3.2
2.3.1
2.3.0
2.2.0
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
2.0.0-beta.1
2.0.0-beta.0
2.0.0-alpha.5
2.0.0-alpha.4
retired
2.0.0-alpha.3
retired
2.0.0-alpha.2
retired
2.0.0-alpha.1
retired
2.0.0-alpha.0
retired
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.1
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
0.17.1
0.17.0
0.16.0
0.15.1
0.15.0
0.14.0
0.13.0-rc.1
0.13.0-rc.0
0.12.1-rc.1
0.12.1-rc.0
0.12.0-rc
0.11.0
0.10.3
0.10.2
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
Authentication library for Phoenix, and other Plug-based, web applications
Current section
Files
Jump to
Current section
Files
lib/phauxth/confirm/base.ex
defmodule Phauxth.Confirm.Base do
@moduledoc """
Base module for handling user / contact confirmation.
This is used by both the Phauxth.Confirm and Phauxth.Confirm.PassReset
modules.
"""
@doc false
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
import Phauxth.Report
alias Phauxth.Token
@doc """
Verify the confirmation key and get the user data from the database.
In the third argument, the key_source is either conn or the name
of the endpoint module, and the max_age is the maximum age of the
key, in minutes.
"""
def verify(%{"key" => key}, user_context, {key_source, max_age}) do
get_user(key_source, {key, max_age * 60, user_context}) |> report
end
def verify(_, _, _), do: report({:error, "no key found"})
def get_user(key_source, {key, max_age, user_context}) do
with {:ok, params} <- Token.verify(key_source, key, max_age: max_age),
do: user_context.get_by(params)
end
@doc """
Print out the log message and return {:ok, user} or {:error, message}.
"""
def report(%{confirmed_at: nil} = user), do: verify_ok(user, "user confirmed")
def report(%{} = user), do: verify_error(user, "user already confirmed")
def report({:error, message}), do: verify_error(message)
def report(nil), do: verify_error(nil)
defoverridable [verify: 3, get_user: 2, report: 1]
end
end
end