mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
Add user accounts, roles, and admin gating
- Scaffold password auth (email or username) with phx.gen.auth; no magic links - Add role (member/moderator/admin/super_admin) and plan (free/premium) enums - Gate /admin behind admin-or-above via plug + on_mount; hide the nav link - Add mix accounts.promote for CLI role changes - Disable email confirmation by confirming accounts at registration Closes #3
This commit is contained in:
@@ -5,6 +5,8 @@ defmodule ChesstrainerWeb.Layouts do
|
||||
"""
|
||||
use ChesstrainerWeb, :html
|
||||
|
||||
alias Chesstrainer.Accounts.Role
|
||||
|
||||
# Embed all files in layouts/* within this module.
|
||||
# The default root.html.heex file contains the HTML
|
||||
# skeleton of your application, namely HTML headers
|
||||
@@ -51,6 +53,10 @@ defmodule ChesstrainerWeb.Layouts do
|
||||
@doc """
|
||||
Renders the application navbar.
|
||||
"""
|
||||
attr :current_scope, :map,
|
||||
default: nil,
|
||||
doc: "the current [scope](https://phoenix.hexdocs.pm/scopes.html)"
|
||||
|
||||
def navbar(assigns) do
|
||||
~H"""
|
||||
<header class="navbar px-4 sm:px-6 lg:px-8">
|
||||
@@ -65,17 +71,32 @@ defmodule ChesstrainerWeb.Layouts do
|
||||
<li>
|
||||
<a href="/endgames" class="btn btn-ghost">Endgames</a>
|
||||
</li>
|
||||
<li>
|
||||
<li :if={@current_scope && Role.admin?(@current_scope.user.role)}>
|
||||
<a href="/admin/endgames" class="btn btn-ghost">Admin</a>
|
||||
</li>
|
||||
<li>
|
||||
<.theme_toggle />
|
||||
</li>
|
||||
<li>
|
||||
<a href="/" class="btn btn-primary">
|
||||
Login / Signup
|
||||
</a>
|
||||
</li>
|
||||
<%= if @current_scope do %>
|
||||
<li>
|
||||
<span class="text-sm">{@current_scope.user.username}</span>
|
||||
</li>
|
||||
<li>
|
||||
<.link navigate={~p"/users/settings"} class="btn btn-ghost">Settings</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/users/log-out"} method="delete" class="btn btn-ghost">
|
||||
Log out
|
||||
</.link>
|
||||
</li>
|
||||
<% else %>
|
||||
<li>
|
||||
<.link navigate={~p"/users/register"} class="btn btn-ghost">Register</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link navigate={~p"/users/log-in"} class="btn btn-primary">Log in</.link>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<Layouts.navbar />
|
||||
<Layouts.navbar current_scope={@current_scope} />
|
||||
{@inner_content}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user