소스 검색

проба ролей

Rimmon 4 년 전
부모
커밋
2c2530af48
2개의 변경된 파일70개의 추가작업 그리고 10개의 파일을 삭제
  1. 1 1
      Pages/Wallet.razor
  2. 69 9
      Shared/Sidebar.razor

+ 1 - 1
Pages/Wallet.razor

@@ -48,7 +48,7 @@
         <a class="tabs__btn">Заказы</a>
     </div>
     <div class="upload">
-        <h2 class="upload__title">Кошелек</h2>
+        <h2 class="upload__title">Кошелек @account.roles.Count; @account.Name</h2>
     </div>
     <table class="table-bordered" cellspacing="5" cellpadding="5">
         <tbody>

+ 69 - 9
Shared/Sidebar.razor

@@ -1,4 +1,55 @@
-<sidebar class="profile-info">
+@namespace HyperCube.Models
+@using Microsoft.AspNetCore.Identity;
+@inject AuthenticationStateProvider AuthenticationStateProvider
+@inject UserManager<IdentityUser> UserManager;
+
+@attribute [Authorize]
+@code
+{ 
+    AccountModel account;
+    List<Role> roles;
+    //string rr = "";
+    //roles = account.roles;
+
+    protected override async Task OnInitializedAsync()
+    {
+        account = await GetCurrentAcc();
+    }
+
+    public async Task InitializeAccount()
+    {
+        AccountModel.Current = await GetCurrentAcc();
+        Console.WriteLine("InitializeAccount in Sidebar " + AccountModel.Current.Name);
+    }
+
+    private async Task<AccountModel> GetCurrentAcc()
+    {
+        AccountModel account = new();
+
+        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
+        var user = authState.User;
+
+        if (user.Identity.IsAuthenticated)
+        {
+            var currentUser = await UserManager.GetUserAsync(user);
+            account.UUID = currentUser.Id;
+            //account.Name = currentUser.UserName;
+            //account.Email = currentUser.Email;
+
+            var acc = AccountModel.Find(account.UUID);
+            if (acc != null)
+                account = acc;
+            ///tmp
+
+            //account.AccRole = Role.User;
+            account.Name = "test";
+            return account;
+        }
+
+        return null;
+    }
+}
+<sidebar class="profile-info">
     <AuthorizeView>
         <Authorized>
             <img src="https://place-hold.it/150x150" alt="Фото профиля" class="profile-info__img">
@@ -11,18 +62,27 @@
                     <div class="profile-info__link">id 00112</div>
                 </div>
                 <div class="profile-info__item">
-                    <a href="Account" class="profile-info__link">
-                        <img src="img/qual.svg" alt="qual" class="profile-info__link-img">
-                        Квалификация
-                    </a>
-                    <a href="#" class="profile-info__link">
-                        <img src="img/rating.svg" alt="qual" class="profile-info__link-img">
-                        Рейтинги
-                    </a>
+                    @if (account.roles.Contains(Role.Initiator))
+                    {
+    <a href="Account" class="profile-info__link">
+        <img src="img/qual.svg" alt="qual" class="profile-info__link-img">
+        Квалификация
+        
+    </a>}
+                <a href="#" class="profile-info__link">
+                    <img src="img/rating.svg" alt="qual" class="profile-info__link-img">
+                    Рейтинги
+                    @account.roles.Count;
+                    @account.Name;
+                </a>
                     <a href="Wallet" class="profile-info__link">
                         <img src="img/wallet.svg" alt="qual" class="profile-info__link-img">
                         Кошелек
                     </a>
+                    <a href="Blockchains" class="profile-info__link">
+                        <img src="img/wallet.svg" alt="qual" class="profile-info__link-img">
+                        Blockchains
+                    </a>
                 </div>
                 <div class="profile-info__item">
                     <a class="profile-info__link">