mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-25 14:34:33 +01:00
mix format
This commit is contained in:
parent
36cbdff953
commit
11cac54ba0
3 changed files with 35 additions and 24 deletions
|
@ -26,18 +26,21 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
|
||||||
@persistent_cookie_signing_salt Atom.to_string(PowPersistentSession.Plug.Cookie)
|
@persistent_cookie_signing_salt Atom.to_string(PowPersistentSession.Plug.Cookie)
|
||||||
|
|
||||||
def init(:load), do: :load
|
def init(:load), do: :load
|
||||||
|
|
||||||
def init(:pow_session) do
|
def init(:pow_session) do
|
||||||
[
|
[
|
||||||
fetch_token: &__MODULE__.client_store_fetch_session/1,
|
fetch_token: &__MODULE__.client_store_fetch_session/1,
|
||||||
namespace: :session
|
namespace: :session
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def init(:pow_persistent_session) do
|
def init(:pow_persistent_session) do
|
||||||
[
|
[
|
||||||
fetch_token: &__MODULE__.client_store_fetch_persistent_cookie/1,
|
fetch_token: &__MODULE__.client_store_fetch_persistent_cookie/1,
|
||||||
namespace: :persistent_session
|
namespace: :persistent_session
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def init({type, opts}) do
|
def init({type, opts}) do
|
||||||
type
|
type
|
||||||
|> init()
|
|> init()
|
||||||
|
@ -49,6 +52,7 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
|
||||||
maybe_load_from_cache(conn, Plug.current_user(conn), opts)
|
maybe_load_from_cache(conn, Plug.current_user(conn), opts)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, opts) do
|
def call(conn, opts) do
|
||||||
fetch_fn = Keyword.fetch!(opts, :fetch_token)
|
fetch_fn = Keyword.fetch!(opts, :fetch_token)
|
||||||
token = fetch_fn.(conn)
|
token = fetch_fn.(conn)
|
||||||
|
@ -68,6 +72,7 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
|
||||||
token -> load_from_cache(conn, token, opts)
|
token -> load_from_cache(conn, token, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_load_from_cache(conn, _any, _opts), do: conn
|
defp maybe_load_from_cache(conn, _any, _opts), do: conn
|
||||||
|
|
||||||
defp put_opts_in_private(conn, opts) do
|
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, nil, _old_token, _opts), do: conn
|
||||||
defp maybe_put_cache(conn, _user, nil, _opts), do: conn
|
defp maybe_put_cache(conn, _user, nil, _opts), do: conn
|
||||||
|
|
||||||
defp maybe_put_cache(conn, user, old_token, opts) do
|
defp maybe_put_cache(conn, user, old_token, opts) do
|
||||||
fetch_fn = Keyword.fetch!(opts, :fetch_token)
|
fetch_fn = Keyword.fetch!(opts, :fetch_token)
|
||||||
|
|
||||||
|
@ -133,7 +139,6 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
|
||||||
else
|
else
|
||||||
_any -> nil
|
_any -> nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp invalidated_cache(conn, opts) do
|
defp invalidated_cache(conn, opts) do
|
||||||
|
@ -150,7 +155,7 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlug do
|
||||||
|
|
||||||
[
|
[
|
||||||
ttl: ttl,
|
ttl: ttl,
|
||||||
namespace: "invalidated_#{namespace}",
|
namespace: "invalidated_#{namespace}"
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -103,9 +103,8 @@ defmodule Search.DateParser do
|
||||||
{[[lower, upper]], context}
|
{[[lower, upper]], context}
|
||||||
|
|
||||||
_false ->
|
_false ->
|
||||||
{:error, "invalid date format in input; requested time #{
|
{:error,
|
||||||
count*scale
|
"invalid date format in input; requested time #{count * scale} seconds is over a millenium ago"}
|
||||||
} seconds is over a millenium ago"}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,11 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlugTest do
|
||||||
setup do
|
setup do
|
||||||
user =
|
user =
|
||||||
%User{authentication_token: "token", name: "John Doe", slug: "john-doe"}
|
%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!()
|
|> Repo.insert!()
|
||||||
|
|
||||||
{:ok, user: user}
|
{:ok, user: user}
|
||||||
|
@ -84,8 +88,12 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlugTest do
|
||||||
defp init_plug(conn, config) do
|
defp init_plug(conn, config) do
|
||||||
conn
|
conn
|
||||||
|> init_session_plug()
|
|> init_session_plug()
|
||||||
|> PowInvalidatedSessionPlug.call(PowInvalidatedSessionPlug.init({:pow_session, ttl: @invalidated_ttl}))
|
|> PowInvalidatedSessionPlug.call(
|
||||||
|> PowInvalidatedSessionPlug.call(PowInvalidatedSessionPlug.init({:pow_persistent_session, ttl: @invalidated_ttl}))
|
PowInvalidatedSessionPlug.init({:pow_session, ttl: @invalidated_ttl})
|
||||||
|
)
|
||||||
|
|> PowInvalidatedSessionPlug.call(
|
||||||
|
PowInvalidatedSessionPlug.init({:pow_persistent_session, ttl: @invalidated_ttl})
|
||||||
|
)
|
||||||
|> Session.call(Session.init(config))
|
|> Session.call(Session.init(config))
|
||||||
|> Cookie.call(Cookie.init([]))
|
|> Cookie.call(Cookie.init([]))
|
||||||
|> PowInvalidatedSessionPlug.call(PowInvalidatedSessionPlug.init(:load))
|
|> PowInvalidatedSessionPlug.call(PowInvalidatedSessionPlug.init(:load))
|
||||||
|
@ -129,7 +137,6 @@ defmodule PhilomenaWeb.PowInvalidatedSessionPlugTest do
|
||||||
|> Conn.send_resp(200, "")
|
|> Conn.send_resp(200, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
defp create_session(conn, user, config) do
|
defp create_session(conn, user, config) do
|
||||||
conn
|
conn
|
||||||
|> init_plug(config)
|
|> init_plug(config)
|
||||||
|
|
Loading…
Reference in a new issue