prevent posting without presenting a _ses cookie

This commit is contained in:
byte[] 2019-12-20 20:30:14 -05:00
parent 3a364bde61
commit ca1150230d

View file

@ -21,13 +21,27 @@ defmodule PhilomenaWeb.FilterBannedUsersPlug do
conn.assigns.current_ban
|> maybe_halt(conn, redirect_url)
|> maybe_halt_no_fingerprint()
end
def maybe_halt(nil, conn, _redirect_url), do: conn
def maybe_halt(_current_ban, conn, redirect_url) do
defp maybe_halt(nil, conn, _redirect_url), do: conn
defp maybe_halt(_current_ban, conn, redirect_url) do
conn
|> Controller.put_flash(:error, "You are currently banned.")
|> Controller.redirect(external: redirect_url)
|> Conn.halt()
end
end
defp maybe_halt_no_fingerprint(%{halted: true} = conn), do: conn
defp maybe_halt_no_fingerprint(conn) do
conn = Conn.fetch_cookies(conn)
case conn.cookies["_ses"] do
nil ->
PhilomenaWeb.NotAuthorizedPlug.call(conn)
_other ->
conn
end
end
end