|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using CraftSharp.Services;
|
|
|
|
|
using CraftSharp.Models;
|
|
|
|
|
using CraftSharp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
@ -11,6 +12,9 @@ namespace CraftSharp.Shared
|
|
|
|
|
[Inject]
|
|
|
|
|
public IStringLocalizer<HeaderLayout> Localizer { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public IAuthService AuthService { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public CustomStateProvider AuthStateProvider { get; set; }
|
|
|
|
|
|
|
|
|
@ -20,6 +24,13 @@ namespace CraftSharp.Shared
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
private Task<AuthenticationState> AuthenticationState { get; set; }
|
|
|
|
|
|
|
|
|
|
private bool isUserAdmin = false;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
isAdmin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void goInscription()
|
|
|
|
|
{
|
|
|
|
|
NavigationManager.NavigateTo("inscription");
|
|
|
|
@ -30,6 +41,13 @@ namespace CraftSharp.Shared
|
|
|
|
|
NavigationManager.NavigateTo("connexion");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async public void isAdmin()
|
|
|
|
|
{
|
|
|
|
|
var authState = await AuthenticationState;
|
|
|
|
|
var roles = AuthService.GetCurrentUser(authState.User.Identity.Name).Roles;
|
|
|
|
|
isUserAdmin = roles.Contains(UserRoles.Admin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* protected override async Task OnParametersSetAsync()
|
|
|
|
|
{
|
|
|
|
|
if (!(await AuthenticationState).User.Identity.IsAuthenticated)
|
|
|
|
|