Account.razor 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. @page "/account"
  2. @using HyperCube.Models;
  3. @using Microsoft.AspNetCore.Identity;
  4. @inject AuthenticationStateProvider AuthenticationStateProvider
  5. @inject UserManager<IdentityUser> UserManager;
  6. @attribute [Authorize]
  7. <h3>Личный кабинет</h3>
  8. <EditForm Model="@account">
  9. <table class="table-bordered" cellspacing="5" cellpadding="5">
  10. <tbody>
  11. <tr>
  12. <td>UUID:</td>
  13. <td>@account.UUID</td>
  14. </tr>
  15. <tr>
  16. <td>Name:</td>
  17. <td>@account.Name</td>
  18. </tr>
  19. <tr>
  20. <td>Email:</td>
  21. <td>@account.Email</td>
  22. </tr>
  23. <tr>
  24. <td>ETH Address:</td>
  25. <td>@account.eth_address</td>
  26. </tr>
  27. <tr>
  28. <td>Balance:</td>
  29. <td>@myBalance WEI</td>
  30. </tr>
  31. </tbody>
  32. </table>
  33. </EditForm>
  34. @code {
  35. private AccountModel account = new();
  36. string myBalance = "";
  37. protected override async Task OnInitializedAsync()
  38. {
  39. account = await GetCurrentAcc();
  40. if (Blockchain.GetMain() != null)
  41. myBalance = await account.GetBalance();
  42. }
  43. private async Task<AccountModel> GetCurrentAcc()
  44. {
  45. AccountModel account = new();
  46. var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
  47. var user = authState.User;
  48. if (user.Identity.IsAuthenticated)
  49. {
  50. var currentUser = await UserManager.GetUserAsync(user);
  51. var acc = AccountModel.Find(currentUser.Id);
  52. if (acc != null)
  53. account = acc;
  54. account.AccRole = Role.User;
  55. return account;
  56. }
  57. return null;
  58. }
  59. }