philomena/lib/philomena_web/plugs/not_authorized_plug.ex

14 lines
337 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)
def call(conn, _opts) do
conn
|> Controller.put_flash(:error, "You can't access that page.")
|> Controller.redirect(to: conn.assigns.referrer)
|> Conn.halt()
end
end