mix format

This commit is contained in:
byte[] 2020-04-11 20:28:28 -04:00
parent 36cbdff953
commit 11cac54ba0
3 changed files with 35 additions and 24 deletions

View file

@ -26,18 +26,21 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
@persistent_cookie_signing_salt Atom.to_string(PowPersistentSession.Plug.Cookie)
def init(:load), do: :load
def init(:pow_session) do
[
fetch_token: &__MODULE__.client_store_fetch_session/1,
namespace: :session
]
end
def init(:pow_persistent_session) do
[
fetch_token: &__MODULE__.client_store_fetch_persistent_cookie/1,
namespace: :persistent_session
]
end
def init({type, opts}) do
type
|> init()
@ -49,6 +52,7 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
maybe_load_from_cache(conn, Plug.current_user(conn), opts)
end)
end
def call(conn, opts) do
fetch_fn = Keyword.fetch!(opts, :fetch_token)
token = fetch_fn.(conn)
@ -68,6 +72,7 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
token -> load_from_cache(conn, token, opts)
end
end
defp maybe_load_from_cache(conn, _any, _opts), do: conn
defp put_opts_in_private(conn, opts) do
@ -78,6 +83,7 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
defp maybe_put_cache(conn, nil, _old_token, _opts), do: conn
defp maybe_put_cache(conn, _user, nil, _opts), do: conn
defp maybe_put_cache(conn, user, old_token, opts) do
fetch_fn = Keyword.fetch!(opts, :fetch_token)
@ -133,7 +139,6 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
else
_any -> nil
end
end
defp invalidated_cache(conn, opts) do
@ -150,7 +155,7 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
[
ttl: ttl,
namespace: "invalidated_#{namespace}",
namespace: "invalidated_#{namespace}"
]
end
end

View file

@ -103,9 +103,8 @@ defmodule Search.DateParser do
{[[lower, upper]], context}
_false ->
{:error, "invalid date format in input; requested time #{
count*scale
} seconds is over a millenium ago"}
{:error,
"invalid date format in input; requested time #{count * scale} seconds is over a millenium ago"}
end
end

View file

@ -19,7 +19,11 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlugTest do
setup do
user =
%User{authentication_token: "token", name: "John Doe", slug: "john-doe"}
|> User.changeset(%{"email" => "test@example.com", "password" => "password", "password_confirmation" => "password"})
|> User.changeset(%{
"email" => "test@example.com",
"password" => "password",
"password_confirmation" => "password"
})
|> Repo.insert!()
{:ok, user: user}
@ -84,8 +88,12 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlugTest do
defp init_plug(conn, config) do
conn
|> init_session_plug()
|> PowInvalidatedSessionPlug.call(PowInvalidatedSessionPlug.init({:pow_session, ttl: @invalidated_ttl}))
|> PowInvalidatedSessionPlug.call(PowInvalidatedSessionPlug.init({:pow_persistent_session, ttl: @invalidated_ttl}))
|> PowInvalidatedSessionPlug.call(
PowInvalidatedSessionPlug.init({:pow_session, ttl: @invalidated_ttl})
)
|> PowInvalidatedSessionPlug.call(
PowInvalidatedSessionPlug.init({:pow_persistent_session, ttl: @invalidated_ttl})
)
|> Session.call(Session.init(config))
|> Cookie.call(Cookie.init([]))
|> PowInvalidatedSessionPlug.call(PowInvalidatedSessionPlug.init(:load))
@ -129,7 +137,6 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlugTest do
|> Conn.send_resp(200, "")
end
defp create_session(conn, user, config) do
conn
|> init_plug(config)