Ajout d'un menu general en haut du site
This commit is contained in:
112
ChessCubing.App/Components/SiteMenu.razor
Normal file
112
ChessCubing.App/Components/SiteMenu.razor
Normal file
@@ -0,0 +1,112 @@
|
||||
@using System.Security.Claims
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<div class="site-menu-shell">
|
||||
<header class="site-menu-bar">
|
||||
<div class="site-menu-main">
|
||||
<a class="site-menu-brand" href="index.html" aria-label="Accueil ChessCubing">
|
||||
<img class="site-menu-brand-icon" src="logo.png" alt="Icone ChessCubing" />
|
||||
<span class="site-menu-brand-copy">
|
||||
<span class="micro-label">ChessCubing Arena</span>
|
||||
<strong>Menu general</strong>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="site-menu-links" aria-label="Navigation principale">
|
||||
<a class="@BuildNavLinkClass(HomePaths)" href="index.html" aria-current="@BuildAriaCurrent(HomePaths)">Accueil</a>
|
||||
<a class="@BuildNavLinkClass(ApplicationPaths)" href="application.html" aria-current="@BuildAriaCurrent(ApplicationPaths)">Application</a>
|
||||
<a class="@BuildNavLinkClass(RulesPaths)" href="reglement.html" aria-current="@BuildAriaCurrent(RulesPaths)">Reglement</a>
|
||||
</nav>
|
||||
|
||||
<AuthorizeView>
|
||||
<Authorized Context="authState">
|
||||
<div class="site-menu-account">
|
||||
<span class="micro-label">Compte Keycloak</span>
|
||||
<div class="site-menu-account-panel">
|
||||
<div class="site-menu-user">
|
||||
<strong>@BuildDisplayName(authState.User)</strong>
|
||||
<span>@BuildMeta(authState.User)</span>
|
||||
</div>
|
||||
<a class="button ghost small" href="@LogoutHref">Se deconnecter</a>
|
||||
</div>
|
||||
</div>
|
||||
</Authorized>
|
||||
<Authorizing>
|
||||
<div class="site-menu-account">
|
||||
<span class="micro-label">Compte Keycloak</span>
|
||||
<div class="site-menu-account-actions">
|
||||
<a class="button secondary small" href="@LoginHref">Se connecter</a>
|
||||
<a class="button ghost small" href="@RegisterHref">Creer un compte</a>
|
||||
</div>
|
||||
</div>
|
||||
</Authorizing>
|
||||
<NotAuthorized>
|
||||
<div class="site-menu-account">
|
||||
<span class="micro-label">Compte Keycloak</span>
|
||||
<div class="site-menu-account-actions">
|
||||
<a class="button secondary small" href="@LoginHref">Se connecter</a>
|
||||
<a class="button ghost small" href="@RegisterHref">Creer un compte</a>
|
||||
</div>
|
||||
</div>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
</header>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private static readonly string[] HomePaths = ["", "index.html"];
|
||||
private static readonly string[] ApplicationPaths = ["application", "application.html"];
|
||||
private static readonly string[] RulesPaths = ["reglement", "reglement.html"];
|
||||
|
||||
private string LoginHref => BuildAuthHref("login", EffectiveReturnUrl);
|
||||
private string RegisterHref => BuildAuthHref("register", EffectiveReturnUrl);
|
||||
private string LogoutHref => BuildAuthHref("logout", "/");
|
||||
|
||||
private string CurrentPath
|
||||
{
|
||||
get
|
||||
{
|
||||
var absolutePath = new Uri(Navigation.Uri).AbsolutePath;
|
||||
return absolutePath.Trim('/');
|
||||
}
|
||||
}
|
||||
|
||||
private string EffectiveReturnUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
var absolutePath = new Uri(Navigation.Uri).AbsolutePath;
|
||||
if (absolutePath.StartsWith("/authentication/", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
return string.IsNullOrWhiteSpace(absolutePath)
|
||||
? "/"
|
||||
: absolutePath;
|
||||
}
|
||||
}
|
||||
|
||||
private string BuildNavLinkClass(string[] paths)
|
||||
=> IsCurrentPage(paths) ? "site-menu-link is-active" : "site-menu-link";
|
||||
|
||||
private string? BuildAriaCurrent(string[] paths)
|
||||
=> IsCurrentPage(paths) ? "page" : null;
|
||||
|
||||
private bool IsCurrentPage(string[] paths)
|
||||
=> paths.Any(path => string.Equals(CurrentPath, path, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
private static string BuildAuthHref(string action, string returnUrl)
|
||||
=> $"authentication/{action}?returnUrl={Uri.EscapeDataString(returnUrl)}";
|
||||
|
||||
private static string BuildDisplayName(ClaimsPrincipal user)
|
||||
=> user.Identity?.Name
|
||||
?? user.FindFirst("name")?.Value
|
||||
?? user.FindFirst("preferred_username")?.Value
|
||||
?? "Utilisateur connecte";
|
||||
|
||||
private static string BuildMeta(ClaimsPrincipal user)
|
||||
=> user.FindFirst("email")?.Value
|
||||
?? "Session active";
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
@using System.Security.Claims
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<AuthorizeView>
|
||||
<Authorized Context="authState">
|
||||
<div class="user-access-bar">
|
||||
<div class="user-access-copy">
|
||||
<span class="micro-label">Compte Keycloak</span>
|
||||
<strong>@BuildDisplayName(authState.User)</strong>
|
||||
<span class="user-access-meta">@BuildMeta(authState.User)</span>
|
||||
</div>
|
||||
<div class="user-access-actions">
|
||||
<a class="button ghost small" href="@LogoutHref">Se deconnecter</a>
|
||||
</div>
|
||||
</div>
|
||||
</Authorized>
|
||||
<Authorizing>
|
||||
<div class="user-access-bar">
|
||||
<div class="user-access-copy">
|
||||
<span class="micro-label">Compte Keycloak</span>
|
||||
<strong>Connexion optionnelle</strong>
|
||||
<span class="user-access-meta">Le site reste accessible sans connexion. Vous pouvez vous connecter ou creer un compte si besoin.</span>
|
||||
</div>
|
||||
<div class="user-access-actions">
|
||||
<a class="button primary small" href="@LoginHref">Se connecter</a>
|
||||
<a class="button ghost small" href="@RegisterHref">Creer un compte</a>
|
||||
</div>
|
||||
</div>
|
||||
</Authorizing>
|
||||
<NotAuthorized>
|
||||
<div class="user-access-bar">
|
||||
<div class="user-access-copy">
|
||||
<span class="micro-label">Compte Keycloak</span>
|
||||
<strong>Connexion optionnelle</strong>
|
||||
<span class="user-access-meta">Le site reste accessible sans connexion. Chaque compte conserve son propre etat de match dans ce navigateur.</span>
|
||||
</div>
|
||||
<div class="user-access-actions">
|
||||
<a class="button primary small" href="@LoginHref">Se connecter</a>
|
||||
<a class="button ghost small" href="@RegisterHref">Creer un compte</a>
|
||||
</div>
|
||||
</div>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? ReturnUrl { get; set; }
|
||||
|
||||
private string LoginHref => BuildAuthHref("login", EffectiveReturnUrl);
|
||||
private string RegisterHref => BuildAuthHref("register", EffectiveReturnUrl);
|
||||
private string LogoutHref => BuildAuthHref("logout", "/");
|
||||
|
||||
private string EffectiveReturnUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(ReturnUrl))
|
||||
{
|
||||
return ReturnUrl!;
|
||||
}
|
||||
|
||||
var relativePath = Navigation.ToBaseRelativePath(Navigation.Uri);
|
||||
if (string.IsNullOrWhiteSpace(relativePath))
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
return relativePath.StartsWith("/", StringComparison.Ordinal)
|
||||
? relativePath
|
||||
: $"/{relativePath}";
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildAuthHref(string action, string returnUrl)
|
||||
=> $"authentication/{action}?returnUrl={Uri.EscapeDataString(returnUrl)}";
|
||||
|
||||
private static string BuildDisplayName(ClaimsPrincipal user)
|
||||
=> user.Identity?.Name
|
||||
?? user.FindFirst("name")?.Value
|
||||
?? user.FindFirst("preferred_username")?.Value
|
||||
?? "Utilisateur connecte";
|
||||
|
||||
private static string BuildMeta(ClaimsPrincipal user)
|
||||
{
|
||||
var details = new List<string>();
|
||||
var email = user.FindFirst("email")?.Value;
|
||||
if (!string.IsNullOrWhiteSpace(email))
|
||||
{
|
||||
details.Add(email);
|
||||
}
|
||||
|
||||
var roles = user.FindAll("role")
|
||||
.Select(claim => claim.Value)
|
||||
.Where(value => !string.IsNullOrWhiteSpace(value))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.OrderBy(value => value, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
|
||||
if (roles.Length > 0)
|
||||
{
|
||||
details.Add($"Roles : {string.Join(", ", roles)}");
|
||||
}
|
||||
|
||||
return details.Count > 0
|
||||
? string.Join(" | ", details)
|
||||
: "Session authentifiee via Keycloak.";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,24 @@
|
||||
@inherits LayoutComponentBase
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@if (!HideGlobalMenu)
|
||||
{
|
||||
<SiteMenu />
|
||||
}
|
||||
|
||||
@Body
|
||||
|
||||
@code {
|
||||
private bool HideGlobalMenu
|
||||
{
|
||||
get
|
||||
{
|
||||
var currentPath = new Uri(Navigation.Uri).AbsolutePath.Trim('/');
|
||||
|
||||
return string.Equals(currentPath, "chrono", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(currentPath, "chrono.html", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(currentPath, "cube", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(currentPath, "cube.html", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
<a class="button ghost" href="index.html">Accueil du site</a>
|
||||
<a class="button secondary" href="reglement.html">Consulter le reglement</a>
|
||||
</div>
|
||||
<UserAccessBar />
|
||||
</div>
|
||||
|
||||
<aside class="hero-preview">
|
||||
|
||||
@@ -28,13 +28,6 @@
|
||||
<a class="button ghost" href="/ethan/">Ouvrir l'appli d'Ethan</a>
|
||||
<a class="button ghost" href="/brice/">Ouvrir l'appli de Brice</a>
|
||||
</div>
|
||||
<div class="hero-account-actions">
|
||||
<span class="micro-label">Compte Keycloak</span>
|
||||
<div class="hero-account-buttons">
|
||||
<a class="button secondary small" href="authentication/login?returnUrl=%2Fapplication.html">Se connecter</a>
|
||||
<a class="button ghost small" href="authentication/register?returnUrl=%2Fapplication.html">Creer un compte</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="hero-preview">
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
<a class="button primary" href="application.html">Ouvrir l'application</a>
|
||||
<a class="button secondary" href="index.html">Retour a l'accueil</a>
|
||||
</div>
|
||||
<UserAccessBar />
|
||||
</div>
|
||||
|
||||
<aside class="hero-preview">
|
||||
|
||||
Reference in New Issue
Block a user