using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Identity; using HyperCube.Pages; using HyperCube.Models; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; namespace HyperCube.Shared { public partial class Sidebar : ComponentBase { [Inject] ProtectedSessionStorage storage { get; set; } [Inject] NavigationManager NavigationManager { get; set; } [Inject] AuthenticationStateProvider AuthenticationStateProvider { get; set; } [Inject] UserManager UserManager { get; set; } ModalProfile modalProfile { get; set; } ModalFiles modalFiles { get; set; } ModalCompetency modalCompetency { get; set; } ModalRating modalRating { get; set; } ModalRules modalRules { get; set; } ModalAssets modalAssets { get; set; } ModalError modalError404 { get; set; } ModalLoading modalLoading { get; set; } AccountModel _currentAccount; protected override async Task OnInitializedAsync() { var acc = await GetCurrentAcc(); Console.WriteLine($"sidebar myFlag set1 {acc.Name}"); //AppData.CurrentAccount = acc; await storage.SetAsync("acc", acc.Email); var myFlag = await storage.GetAsync("acc"); Console.WriteLine($"sidebar myFlag set {myFlag.Value}"); await storage.SetAsync("completed", true); } void LogoClick() { NavigationManager.NavigateTo(""); } async Task ProfileClick() { //AccountModel account = new() { Name = "[SomeUserName]", UUID = "[SomeUserID]" }; AccountModel account = await GetCurrentAcc(); account.LoadRoles(); modalProfile.Open(account); } void DesktopClick() { NavigationManager.NavigateTo("desktop"); } void FilesClick() { modalFiles.Open(); } void CompetencyClick() { modalCompetency.Open(); } void RatingClick() { modalRating.Open(); } void RulesClick() { modalRules.Open(); } async Task AssetsClick() { await modalAssets.Open(_currentAccount); } void ExitClick() { NavigationManager.NavigateTo("Identity/Account/Logout", true); } void ErrorClick() { modalError404.Open(); } async Task GetCurrentAcc() { if (_currentAccount == null) { var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); var user = authState.User; if (user.Identity.IsAuthenticated) { var currentUser = await UserManager.GetUserAsync(user); var acc = AccountModel.Find(currentUser.Id); if (acc != null) { _currentAccount = AccountModel.Loaded[currentUser.Id]; } else { Dictionary accounts = await MySQLConnector.Instance().SQLSelectASPUsers(); if (accounts.ContainsKey(currentUser.Id)) _currentAccount = accounts[currentUser.Id]; } } } return _currentAccount; } } }