mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
email signup up flow in dev mode, therefore in place for prod
This commit is contained in:
@@ -7,6 +7,7 @@ defmodule Chesstrainer.Accounts.UserToken do
|
||||
@rand_size 32
|
||||
|
||||
@change_email_validity_in_days 7
|
||||
@confirm_validity_in_days 1
|
||||
@session_validity_in_days 14
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@@ -121,6 +122,31 @@ defmodule Chesstrainer.Accounts.UserToken do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Checks if the token is valid and returns its underlying lookup query.
|
||||
|
||||
The query returns the user_token found by the token, if any.
|
||||
|
||||
This is used to validate requests to confirm the user account.
|
||||
The given token is valid if it matches its hashed counterpart in the
|
||||
database and if it has not expired (after @confirm_validity_in_days).
|
||||
"""
|
||||
def verify_confirmation_token_query(token) do
|
||||
case Base.url_decode64(token, padding: false) do
|
||||
{:ok, decoded_token} ->
|
||||
hashed_token = :crypto.hash(@hash_algorithm, decoded_token)
|
||||
|
||||
query =
|
||||
from token in by_token_and_context_query(hashed_token, "confirm"),
|
||||
where: token.inserted_at > ago(@confirm_validity_in_days, "day")
|
||||
|
||||
{:ok, query}
|
||||
|
||||
:error ->
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
defp by_token_and_context_query(token, context) do
|
||||
from UserToken, where: [token: ^token, context: ^context]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user