mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-18 06:57:59 +01:00
21 lines
404 B
Elixir
21 lines
404 B
Elixir
defmodule PhilomenaWeb.RequireUserPlug do
|
|
import Phoenix.Controller
|
|
import Plug.Conn
|
|
|
|
# No options
|
|
def init([]), do: false
|
|
|
|
# Redirect if not logged in
|
|
def call(conn, _opts) do
|
|
user = conn.assigns.current_user
|
|
|
|
if user do
|
|
conn
|
|
else
|
|
conn
|
|
|> put_flash(:alert, "You must be signed in to see this page.")
|
|
|> redirect(to: "/")
|
|
|> halt()
|
|
end
|
|
end
|
|
end
|