Create new layout for pages with authorization checks
This commit is contained in:
22
Hcs.WebApp/Components/Layout/AuthorizedLayout.razor
Normal file
22
Hcs.WebApp/Components/Layout/AuthorizedLayout.razor
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
|
|
||||||
|
@layout MainLayout
|
||||||
|
|
||||||
|
<AuthorizeView Roles="@Roles">
|
||||||
|
<Authorized>
|
||||||
|
<CascadingValue Value="this">
|
||||||
|
@Body
|
||||||
|
</CascadingValue>
|
||||||
|
</Authorized>
|
||||||
|
<NotAuthorized>
|
||||||
|
<RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" Variant="Variant.Flat" Shade="Shade.Lighter">
|
||||||
|
У вас нет прав для доступа к этой странице
|
||||||
|
</RadzenAlert>
|
||||||
|
</NotAuthorized>
|
||||||
|
</AuthorizeView>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
public string Roles { get; set; }
|
||||||
|
}
|
||||||
@ -9,18 +9,19 @@
|
|||||||
@using Hcs.WebApp.Utils
|
@using Hcs.WebApp.Utils
|
||||||
@using Microsoft.AspNetCore.Authorization
|
@using Microsoft.AspNetCore.Authorization
|
||||||
|
|
||||||
@implements IDisposable
|
|
||||||
|
|
||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
|
|
||||||
|
@layout AuthorizedLayout
|
||||||
|
|
||||||
|
@implements IDisposable
|
||||||
|
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject IConfiguration Configuration
|
@inject IConfiguration Configuration
|
||||||
@inject IClientProvider ClientProvider
|
@inject IClientProvider ClientProvider
|
||||||
|
|
||||||
<PageTitle>Тестирование экспорта</PageTitle>
|
<PageTitle>Тестирование экспорта</PageTitle>
|
||||||
|
|
||||||
<AuthorizeView Roles="@AppRole.ADMINISTRATOR_TYPE">
|
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);">
|
||||||
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);">
|
|
||||||
<RadzenSplitterPane Size="200px">
|
<RadzenSplitterPane Size="200px">
|
||||||
<div style="height: 100%;overflow: auto;">
|
<div style="height: 100%;overflow: auto;">
|
||||||
<RadzenCardGroup Responsive="true">
|
<RadzenCardGroup Responsive="true">
|
||||||
@ -50,8 +51,7 @@
|
|||||||
<RadzenSplitterPane Size="auto" Resizable="false">
|
<RadzenSplitterPane Size="auto" Resizable="false">
|
||||||
<EventConsole @ref=@console />
|
<EventConsole @ref=@console />
|
||||||
</RadzenSplitterPane>
|
</RadzenSplitterPane>
|
||||||
</RadzenSplitter>
|
</RadzenSplitter>
|
||||||
</AuthorizeView>
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
EventConsole console = default!;
|
EventConsole console = default!;
|
||||||
@ -66,10 +66,15 @@
|
|||||||
FileMessageCapturer messageCapturer;
|
FileMessageCapturer messageCapturer;
|
||||||
bool catchMessageBody;
|
bool catchMessageBody;
|
||||||
|
|
||||||
|
[CascadingParameter]
|
||||||
|
public AuthorizedLayout Layout { get; set; }
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
|
|
||||||
|
Layout.Roles = AppRole.ADMINISTRATOR_TYPE;
|
||||||
|
|
||||||
logger.OnWriteLine += OnLog;
|
logger.OnWriteLine += OnLog;
|
||||||
|
|
||||||
messageCapturer = new FileMessageCapturer("test/export", logger);
|
messageCapturer = new FileMessageCapturer("test/export", logger);
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
@using System.Net.Http.Json
|
@using System.Net.Http.Json
|
||||||
@using Hcs.WebApp
|
@using Hcs.WebApp
|
||||||
@using Hcs.WebApp.Components
|
@using Hcs.WebApp.Components
|
||||||
|
@using Hcs.WebApp.Components.Layout
|
||||||
@using Hcs.WebApp.Components.Shared
|
@using Hcs.WebApp.Components.Shared
|
||||||
@using Hcs.WebApp.Data
|
@using Hcs.WebApp.Data
|
||||||
@using Microsoft.AspNetCore.Components.Authorization
|
@using Microsoft.AspNetCore.Components.Authorization
|
||||||
|
|||||||
Reference in New Issue
Block a user