philomena/lib/philomena_web/plugs/not_authorized_plug.ex

17 lines
377 B
Elixir
Raw Normal View History

2019-12-02 03:30:58 +01:00
defmodule PhilomenaWeb.NotAuthorizedPlug do
alias Phoenix.Controller
alias Plug.Conn
def init([]), do: []
def call(conn), do: call(conn, nil)
2020-01-11 05:20:19 +01:00
2019-12-02 03:30:58 +01:00
def call(conn, _opts) do
conn
2019-12-15 04:25:11 +01:00
|> Controller.fetch_flash()
2019-12-02 03:30:58 +01:00
|> Controller.put_flash(:error, "You can't access that page.")
2019-12-04 13:38:57 +01:00
|> Controller.redirect(external: conn.assigns.referrer)
2019-12-02 03:30:58 +01:00
|> Conn.halt()
end
2019-12-15 04:25:11 +01:00
end