2019-12-01 21:30:58 -05:00
|
|
|
defmodule PhilomenaWeb.NotAuthorizedPlug do
|
|
|
|
alias Phoenix.Controller
|
|
|
|
alias Plug.Conn
|
|
|
|
|
|
|
|
def init([]), do: []
|
|
|
|
|
|
|
|
def call(conn), do: call(conn, nil)
|
2020-01-10 23:20:19 -05:00
|
|
|
|
2019-12-01 21:30:58 -05:00
|
|
|
def call(conn, _opts) do
|
2020-09-27 23:53:14 -04:00
|
|
|
case conn.assigns.ajax? do
|
|
|
|
true ->
|
|
|
|
conn
|
|
|
|
|> Conn.resp(:forbidden, "You can't access that page.")
|
|
|
|
|> Conn.halt()
|
|
|
|
|
|
|
|
_false ->
|
|
|
|
conn
|
|
|
|
|> Controller.fetch_flash()
|
|
|
|
|> Controller.put_flash(:error, "You can't access that page.")
|
|
|
|
|> Controller.redirect(to: "/")
|
|
|
|
|> Conn.halt()
|
|
|
|
end
|
2019-12-01 21:30:58 -05:00
|
|
|
end
|
2019-12-14 22:25:11 -05:00
|
|
|
end
|