Account.razor 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. <tr>
  32. <td>Администратор:<input @bind="radio" type="checkbox" name="имя1" атрибуты></td>
  33. @radio
  34. </tr>
  35. <tr>
  36. <td>Инициатор:<input type="checkbox" name="имя2" атрибуты></td>
  37. </tr>
  38. <tr>
  39. <td>Верификатор:<input type="checkbox" name="имя3" атрибуты></td>
  40. </tr>
  41. <tr>
  42. <td>Заказчик:<input type="checkbox" name="имя4" атрибуты></td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. </EditForm>
  47. @code {
  48. private AccountModel account = new();
  49. string myBalance = "";
  50. string radio;
  51. protected override async Task OnInitializedAsync()
  52. {
  53. account = await GetCurrentAcc();
  54. if (Blockchain.GetMain() != null)
  55. myBalance = await account.GetBalance();
  56. }
  57. private async Task<AccountModel> GetCurrentAcc()
  58. {
  59. AccountModel account = new();
  60. var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
  61. var user = authState.User;
  62. if (user.Identity.IsAuthenticated)
  63. {
  64. var currentUser = await UserManager.GetUserAsync(user);
  65. var acc = AccountModel.Find(currentUser.Id);
  66. if (acc != null)
  67. account = acc;
  68. account.AccRole = Role.User;
  69. return account;
  70. }
  71. return null;
  72. }
  73. }