summaryrefslogtreecommitdiff
path: root/lib/nola/token.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nola/token.ex')
-rw-r--r--lib/nola/token.ex24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/nola/token.ex b/lib/nola/token.ex
index 179bed2..f4fdd86 100644
--- a/lib/nola/token.ex
+++ b/lib/nola/token.ex
@@ -2,15 +2,15 @@ defmodule Nola.Token do
use GenServer
def start_link() do
- GenServer.start_link(__MODULE__, [], [name: __MODULE__])
+ GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
def lookup(id) do
- with \
- [{_, cred, date}] <- :ets.lookup(__MODULE__.ETS, id),
- IO.inspect("cred: #{inspect cred} valid for #{inspect date} now #{inspect DateTime.utc_now()}"),
- d when d > 0 <- DateTime.diff(date, DateTime.utc_now())
- do
+ with [{_, cred, date}] <- :ets.lookup(__MODULE__.ETS, id),
+ IO.inspect(
+ "cred: #{inspect(cred)} valid for #{inspect(date)} now #{inspect(DateTime.utc_now())}"
+ ),
+ d when d > 0 <- DateTime.diff(date, DateTime.utc_now()) do
{:ok, cred}
else
err -> {:error, err}
@@ -22,17 +22,21 @@ defmodule Nola.Token do
end
def init(_) do
- ets = :ets.new(__MODULE__.ETS, [:ordered_set, :named_table, :protected, {:read_concurrency, true}])
+ ets =
+ :ets.new(__MODULE__.ETS, [:ordered_set, :named_table, :protected, {:read_concurrency, true}])
+
{:ok, ets}
end
def handle_call({:new, cred}, _, ets) do
id = Nola.UserTrack.Id.large_id()
- expire = DateTime.utc_now()
- |> DateTime.add(15*60, :second)
+
+ expire =
+ DateTime.utc_now()
+ |> DateTime.add(15 * 60, :second)
+
obj = {id, cred, expire}
:ets.insert(ets, obj)
{:reply, {:ok, id}, ets}
end
-
end