* Changed views to have them in the same layout
* Added Authorization
This commit is contained in:
@@ -1,50 +1,87 @@
|
||||
@using Syncfusion.Blazor.Navigations
|
||||
@using Syncfusion.Blazor.SplitButtons
|
||||
@using Orientation = Syncfusion.Blazor.Navigations.Orientation
|
||||
@inject NavigationManager NavigationManager
|
||||
@inherits LayoutComponentBase
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<div class="page h-100">
|
||||
@using System.Security.Claims
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using Syncfusion.Blazor.Navigations
|
||||
@using static Syncfusion.Blazor.Navigations.Orientation
|
||||
@using Syncfusion.Blazor.Buttons
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject CustomAuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
<div class="page h-100 d-flex flex-column">
|
||||
<main class="container-fluid d-flex flex-column h-100">
|
||||
<div class="bb-top-row px-4 d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="bb-top-row px-4 d-flex justify-content-between align-items-center mb-3 shadow-sm"
|
||||
style="background-color: #f8f9fa;">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="logo.svg" class="me-2" width="35" height="35" alt="Icon">
|
||||
<span>FA Krosno Manager</span>
|
||||
<h3 class="text-primary m-0">FA Krosno Manager</h3>
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
@if (IsAuthenticated)
|
||||
{
|
||||
<span class="me-2">Jesteś zalogowany jako <strong>@UserName</strong></span>
|
||||
<SfButton CssClass="e-primary" IsPrimary="true" @onclick="Logout">Wyloguj</SfButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a href="/login" class="text-muted">Zaloguj</a>
|
||||
}
|
||||
</div>
|
||||
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
|
||||
</div>
|
||||
<div class="row gx-1 flex-grow-1">
|
||||
<div class="col-auto custom-menu-width mb-3">
|
||||
<SfMenu HamburgerMode="true" Title="FA Krosno Manager" Items="@MenuItems"
|
||||
Orientation="Orientation.Vertical" CssClass="custom-menu">
|
||||
<MenuEvents TValue="MenuItem" ItemSelected="OnMenuItemSelected"></MenuEvents>
|
||||
<MenuFieldSettings Text="Text" Children="Children"></MenuFieldSettings>
|
||||
<div class="col-auto custom-menu-width">
|
||||
<SfMenu TValue="MenuItem" HamburgerMode="true" Orientation="Vertical" Title="Menu">
|
||||
<MenuItems>
|
||||
<MenuItem Text="Zamówienia DELFOR" Url="/ScheduleOrders" IconCss="fa-solid fa-landmark"></MenuItem>
|
||||
<MenuItem Text="Zamówienia klienta EDI" Url="/EdiCustomerOrders" IconCss="fa-solid fa-list-check"></MenuItem>
|
||||
<MenuItem Text="Zamówienia klienta" Url="/CustomerOrders" IconCss="fa-solid fa-database"></MenuItem>
|
||||
@if (UserName == "pkus")
|
||||
{
|
||||
<MenuItem Text="Admin" IconCss="fa-solid fa-screwdriver-wrench">
|
||||
<MenuItems>
|
||||
<MenuItem Text = "Użytkownicy" Url = "/Admin/UsersManager" IconCss="fa-solid fa-user-tie"></MenuItem>
|
||||
<MenuItem Text= "Scheduler" Url = "/Admin/Scheduler" IconCss="fa-solid fa-calendar-week"></MenuItem>
|
||||
</MenuItems>
|
||||
</MenuItem>
|
||||
}
|
||||
</MenuItems>
|
||||
<MenuAnimationSettings Effect="MenuEffect.SlideDown" Duration="800"></MenuAnimationSettings>
|
||||
</SfMenu>
|
||||
</div>
|
||||
<article class="content col d-flex flex-column">
|
||||
<div class="py-2 flex-grow-1">@Body</div>
|
||||
<footer class="text-center text-muted py-2">
|
||||
<small>FA Krosno Manager © @(DateTime.Now.Year)</small>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
@code {
|
||||
private List<MenuItem> MenuItems { get; set; } = new();
|
||||
private bool IsAuthenticated { get; set; }
|
||||
private string UserName { get; set; } = string.Empty;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
MenuItems = new List<MenuItem>
|
||||
{
|
||||
new() { Text = "Zamówienia DELFOR", Url = "/ScheduleOrders", IconCss = "fa-solid fa-landmark" },
|
||||
new() { Text = "Zamówienia klienta EDI", Url = "/EdiCustomerOrders", IconCss = "fa-solid fa-list-check" },
|
||||
new() { Text = "Zamówienia klienta", Url = "/CustomerOrders", IconCss = "fa-solid fa-database" }
|
||||
};
|
||||
ClaimsPrincipal currentUser = AuthenticationStateProvider.GetCurrentUser();
|
||||
IsAuthenticated = currentUser.Identity?.IsAuthenticated == true;
|
||||
UserName = currentUser.Identity?.Name ?? "Nieznany użytkownik";
|
||||
|
||||
AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
|
||||
}
|
||||
|
||||
private void OnMenuItemSelected(MenuEventArgs<MenuItem> args)
|
||||
private async void OnAuthenticationStateChanged(Task<AuthenticationState> task)
|
||||
{
|
||||
NavigationManager.NavigateTo(args.Item.Url);
|
||||
var authState = await task;
|
||||
IsAuthenticated = authState.User.Identity?.IsAuthenticated ?? false;
|
||||
UserName = IsAuthenticated ? authState.User.Identity?.Name ?? "Nieznany użytkownik" : string.Empty;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void Logout()
|
||||
{
|
||||
NavigationManager.NavigateTo("/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user