Sidebar.razor 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. @namespace HyperCube.Models
  2. @using Microsoft.AspNetCore.Identity;
  3. @inject AuthenticationStateProvider AuthenticationStateProvider
  4. @inject UserManager<IdentityUser> UserManager;
  5. @attribute [Authorize]
  6. @code
  7. {
  8. AccountModel account;
  9. List<Role> roles;
  10. //string rr = "";
  11. //roles = account.roles;
  12. protected override async Task OnInitializedAsync()
  13. {
  14. account = await GetCurrentAcc();
  15. }
  16. public async Task InitializeAccount()
  17. {
  18. AccountModel.Current = await GetCurrentAcc();
  19. Console.WriteLine("InitializeAccount in Sidebar " + AccountModel.Current.Name);
  20. }
  21. private async Task<AccountModel> GetCurrentAcc()
  22. {
  23. AccountModel account = new();
  24. var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
  25. var user = authState.User;
  26. if (user.Identity.IsAuthenticated)
  27. {
  28. var currentUser = await UserManager.GetUserAsync(user);
  29. account.UUID = currentUser.Id;
  30. //account.Name = currentUser.UserName;
  31. //account.Email = currentUser.Email;
  32. var acc = AccountModel.Find(account.UUID);
  33. if (acc != null)
  34. account = acc;
  35. ///tmp
  36. //account.AccRole = Role.User;
  37. account.Name = "test";
  38. return account;
  39. }
  40. return null;
  41. }
  42. }
  43. <sidebar class="profile-info">
  44. <AuthorizeView>
  45. <Authorized>
  46. <img src="https://place-hold.it/150x150" alt="Фото профиля" class="profile-info__img">
  47. <div class="profile-info__list">
  48. <div class="profile-info__item">
  49. <div class="profile-info__link">Имя: @context.User.Identity.Name</div>
  50. <div class="profile-info__link">Фамилия: @context.User.Identity.Name</div>
  51. </div>
  52. <div class="profile-info__item">
  53. <div class="profile-info__link">id 00112</div>
  54. </div>
  55. <div class="profile-info__item">
  56. @if (account.roles.Contains(Role.Initiator))
  57. {
  58. <a href="Account" class="profile-info__link">
  59. <img src="img/qual.svg" alt="qual" class="profile-info__link-img">
  60. Квалификация
  61. </a>}
  62. <a href="#" class="profile-info__link">
  63. <img src="img/rating.svg" alt="qual" class="profile-info__link-img">
  64. Рейтинги
  65. @account.roles.Count;
  66. @account.Name;
  67. </a>
  68. <a href="Wallet" class="profile-info__link">
  69. <img src="img/wallet.svg" alt="qual" class="profile-info__link-img">
  70. Кошелек
  71. </a>
  72. <a href="Blockchains" class="profile-info__link">
  73. <img src="img/wallet.svg" alt="qual" class="profile-info__link-img">
  74. Blockchains
  75. </a>
  76. </div>
  77. <div class="profile-info__item">
  78. <a class="profile-info__link">
  79. <img src="img/exit.svg" alt="qual" class="profile-info__link-img">
  80. <form method="post" action="Identity/Account/LogOut">
  81. <button type="submit" class="nav-link btn btn-link">Выйти</button>
  82. </form>
  83. </a>
  84. </div>
  85. </div>
  86. </Authorized>
  87. <NotAuthorized>
  88. <a class="profile-info__link" href="Identity/Account/Register">Регистрация</a>
  89. <a class="profile-info__link" href="Identity/Account/Login">Вход</a>
  90. </NotAuthorized>
  91. </AuthorizeView>
  92. </sidebar>