Sidebar.razor.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Microsoft.AspNetCore.Components;
  5. using Microsoft.AspNetCore.Components.Authorization;
  6. using Microsoft.AspNetCore.Identity;
  7. using HyperCube.Pages;
  8. using HyperCube.Models;
  9. using Console = HyperCube.Utils.AdvConsole;
  10. namespace HyperCube.Shared
  11. {
  12. public partial class Sidebar : ComponentBase
  13. {
  14. [Inject]
  15. NavigationManager NavigationManager { get; set; }
  16. [Inject]
  17. AuthenticationStateProvider AuthenticationStateProvider { get; set; }
  18. [Inject]
  19. UserManager<IdentityUser> UserManager { get; set; }
  20. ModalProfile modalProfile { get; set; }
  21. ModalFiles modalFiles { get; set; }
  22. ModalCompetency modalCompetency { get; set; }
  23. ModalRating modalRating { get; set; }
  24. ModalRules modalRules { get; set; }
  25. ModalAssets modalAssets { get; set; }
  26. ModalInfo modalError404 { get; set; }
  27. ModalLoading modalLoading { get; set; }
  28. AccountModel _currentAccount;
  29. protected override async Task OnInitializedAsync()
  30. {
  31. }
  32. async Task ProfileClick()
  33. {
  34. //AccountModel account = new() { Name = "[SomeUserName]", UUID = "[SomeUserID]" };
  35. AccountModel account = await GetCurrentAcc();
  36. account.LoadRoles();
  37. modalProfile.Open(account);
  38. }
  39. void FilesClick()
  40. {
  41. modalFiles.Open();
  42. }
  43. void CompetencyClick()
  44. {
  45. modalCompetency.Open();
  46. }
  47. void RatingClick()
  48. {
  49. modalRating.Open();
  50. }
  51. void RulesClick()
  52. {
  53. modalRules.Open();
  54. }
  55. void AssetsClick()
  56. {
  57. modalAssets.Open();
  58. }
  59. void ExitClick()
  60. {
  61. NavigationManager.NavigateTo("Identity/Account/Logout", true);
  62. }
  63. void ErrorClick()
  64. {
  65. modalError404.Open();
  66. }
  67. async Task<AccountModel> GetCurrentAcc()
  68. {
  69. if (_currentAccount == null)
  70. {
  71. var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
  72. var user = authState.User;
  73. if (user.Identity.IsAuthenticated)
  74. {
  75. ///tmp
  76. Dictionary<string, AccountModel> accounts = await MySQLConnector.Instance().SQLSelectASPUsers();
  77. var currentUser = await UserManager.GetUserAsync(user);
  78. if (accounts.ContainsKey(currentUser.Id))
  79. _currentAccount = accounts[currentUser.Id];
  80. }
  81. }
  82. return _currentAccount;
  83. }
  84. }
  85. }