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,17 +9,18 @@
|
||||
@using Hcs.WebApp.Utils
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
@layout AuthorizedLayout
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IConfiguration Configuration
|
||||
@inject IClientProvider ClientProvider
|
||||
|
||||
<PageTitle>Тестирование экспорта</PageTitle>
|
||||
|
||||
<AuthorizeView Roles="@AppRole.ADMINISTRATOR_TYPE">
|
||||
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);">
|
||||
<RadzenSplitterPane Size="200px">
|
||||
<div style="height: 100%;overflow: auto;">
|
||||
@ -51,7 +52,6 @@
|
||||
<EventConsole @ref=@console />
|
||||
</RadzenSplitterPane>
|
||||
</RadzenSplitter>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
EventConsole console = default!;
|
||||
@ -66,10 +66,15 @@
|
||||
FileMessageCapturer messageCapturer;
|
||||
bool catchMessageBody;
|
||||
|
||||
[CascadingParameter]
|
||||
public AuthorizedLayout Layout { get; set; }
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
Layout.Roles = AppRole.ADMINISTRATOR_TYPE;
|
||||
|
||||
logger.OnWriteLine += OnLog;
|
||||
|
||||
messageCapturer = new FileMessageCapturer("test/export", logger);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
@using System.Net.Http.Json
|
||||
@using Hcs.WebApp
|
||||
@using Hcs.WebApp.Components
|
||||
@using Hcs.WebApp.Components.Layout
|
||||
@using Hcs.WebApp.Components.Shared
|
||||
@using Hcs.WebApp.Data
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
|
||||
Reference in New Issue
Block a user