Files
mapo-core/MP.Prog/Components/CmpTop.razor.cs
T
Samuele Locatelli d9fa23b17b PROG:
- Aggiunta preliminare gestione UserName
- verifica gestione auth windows
- update in prod
2024-10-22 12:06:25 +02:00

90 lines
2.1 KiB
C#

using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;
//using MP.Prog.Components;
//using System.Security.Claims;
//using Microsoft.AspNetCore.Components.Authorization;
using MP.Prog.Data;
using System;
using Microsoft.AspNetCore.Components.Authorization;
namespace MP.Prog.Components
{
public partial class CmpTop
{
#region Public Methods
public void Dispose()
{
MServ.EA_PageUpdated -= OnPageUpdate;
}
public void OnPageUpdate()
{
PageName = MServ.PageName;
PageIcon = MServ.PageIcon;
InvokeAsync(() =>
{
StateHasChanged();
});
}
#endregion Public Methods
#region Protected Properties
[Inject]
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; }
[Inject]
protected MessageService MServ { get; set; }
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
MServ.EA_PageUpdated += OnPageUpdate;
await forceReload();
}
#endregion Protected Methods
#region Private Properties
private string PageIcon { get; set; }
private string PageName { get; set; }
[CascadingParameter(Name = "ShowSearch")]
private bool ShowSearch { get; set; }
private string UserName
{
get => MServ.UserName;
set => MServ.UserName = value;
}
#endregion Private Properties
#region Private Methods
private async Task forceReload()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
if (user.Identity != null && user.Identity.IsAuthenticated)
{
UserName = $"{user.Identity.Name}";
}
else
{
UserName = "";
}
}
#endregion Private Methods
}
}