Protection routes

arthur_usercookies
Arthur VALIN 2 years ago
parent 7a0a4e4204
commit 249df5cfe0

@ -1,15 +1,18 @@
@page "/list"
@using CraftSharp.Models
<h3>@Localizer["Title"]</h3>
@if (AuthStateProvider.GetCurrentUser().Roles.Contains(UserRoles.Admin))
{
<div>
<h3>@Localizer["Title"]</h3>
<div>
<NavLink class="btn btn-primary" href="Add" Match="NavLinkMatch.All">
<i class="fa fa-plus"></i> @Localizer["Add"]
</NavLink>
</div>
</div>
<DataGrid TItem="Item"
<DataGrid TItem="Item"
Data="@items"
ReadData="@OnReadData"
TotalItems="@totalItem"
@ -49,4 +52,8 @@
<button type="button" class="btn btn-primary" @onclick="() => OnDelete(context.Id)"><i class="fa fa-trash"></i> @Localizer["Supp"]</button>
</DisplayTemplate>
</DataGridColumn>
</DataGrid>
</DataGrid>
}else{
<p>FORBIDDEN !!</p>
}

@ -16,6 +16,9 @@ namespace CraftSharp.Pages
private int totalItem;
[Inject]
public CustomStateProvider AuthStateProvider { get; set; }
[Inject]
public IStringLocalizer<List> Localizer { get; set; }

@ -11,7 +11,6 @@
</div>
</Authorized>
</AuthorizeView>
@AuthStateProvider.GetCurrentUser().UserName;
<div class="openingPanel">
<img src="/Images/chestBottom.png" class="chest chestOpenBottom @openAnim" />
<img src="/Images/chest.png" class="chest chestOpen @openAnim" />

@ -29,6 +29,10 @@ namespace CraftSharp.Shared
protected override async Task OnInitializedAsync()
{
if (AuthStateProvider.GetCurrentUser() == null || !AuthStateProvider.GetCurrentUser().IsAuthenticated)
{
NavigationManager.NavigateTo("/");
}
isAdmin();
}

Loading…
Cancel
Save