summaryrefslogtreecommitdiff
path: root/lib/nola/auth_token.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nola/auth_token.ex')
-rw-r--r--lib/nola/auth_token.ex21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/nola/auth_token.ex b/lib/nola/auth_token.ex
index 9760ec7..0da4aab 100644
--- a/lib/nola/auth_token.ex
+++ b/lib/nola/auth_token.ex
@@ -2,7 +2,7 @@ defmodule Nola.AuthToken do
use GenServer
def start_link() do
- GenServer.start_link(__MODULE__, [], [name: __MODULE__])
+ GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
def lookup(id) do
@@ -13,6 +13,7 @@ defmodule Nola.AuthToken do
case new(account, perks) do
{:ok, id} ->
NolaWeb.Router.Helpers.login_path(NolaWeb.Endpoint, :token, id)
+
error ->
error
end
@@ -22,6 +23,7 @@ defmodule Nola.AuthToken do
case new(account, perks) do
{:ok, id} ->
NolaWeb.Router.Helpers.login_url(NolaWeb.Endpoint, :token, id)
+
error ->
error
end
@@ -32,15 +34,14 @@ defmodule Nola.AuthToken do
end
def init(_) do
- {:ok, Map.new}
+ {:ok, Map.new()}
end
def handle_call({:lookup, id}, _, state) do
IO.inspect(state)
- with \
- {account, date, perks} <- Map.get(state, id),
- d when d > 0 <- DateTime.diff(date, DateTime.utc_now())
- do
+
+ with {account, date, perks} <- Map.get(state, id),
+ d when d > 0 <- DateTime.diff(date, DateTime.utc_now()) do
{:reply, {:ok, account, perks}, Map.delete(state, id)}
else
x ->
@@ -51,9 +52,11 @@ defmodule Nola.AuthToken do
def handle_call({:new, account, perks}, _, state) do
id = Nola.UserTrack.Id.token()
- expire = DateTime.utc_now()
- |> DateTime.add(15*60, :second)
+
+ expire =
+ DateTime.utc_now()
+ |> DateTime.add(15 * 60, :second)
+
{:reply, {:ok, id}, Map.put(state, id, {account, expire, perks})}
end
-
end