This commit is contained in:
zack 2024-10-21 19:20:35 -04:00
parent 561ea7543d
commit 43e6b6d318
No known key found for this signature in database
GPG key ID: 5F873416BCF59F35
25 changed files with 8063 additions and 374 deletions

View file

@ -195,6 +195,31 @@ defmodule ZoeyscomputerWeb.UserAuth do
end
end
@doc """
Used for routes that require an admin user.
Currently used for the `/dev/` routes.
"""
def require_authenticated_admin_user(conn, _opts) do
if conn.assigns[:current_user] do
if conn.assigns[:current_user].admin do
conn
else
conn
|> put_flash(:error, "You must be an admin to access this page.")
|> maybe_store_return_to()
|> redirect(to: ~p"/")
|> halt()
end
else
conn
|> put_flash(:error, "You must log in to access this page.")
|> maybe_store_return_to()
|> redirect(to: ~p"/users/log_in")
|> halt()
end
end
@doc """
Used for routes that require the user to be authenticated.