mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
23 lines
421 B
Elixir
23 lines
421 B
Elixir
|
defmodule PhilomenaWeb.Plugs.RequireUser do
|
||
|
import Phoenix.Controller
|
||
|
import Plug.Conn
|
||
|
import Pow.Plug
|
||
|
|
||
|
# No options
|
||
|
def init([]), do: false
|
||
|
|
||
|
# Redirect if not logged in
|
||
|
def call(conn, _opts) do
|
||
|
user = conn |> current_user()
|
||
|
|
||
|
if user do
|
||
|
conn
|
||
|
else
|
||
|
conn
|
||
|
|> put_flash(:error, "You must be signed in to see this page.")
|
||
|
|> redirect(to: "/")
|
||
|
|> halt()
|
||
|
end
|
||
|
end
|
||
|
end
|