Sfoglia il codice sorgente

че-то собрал в первом приближении

Rimmon 2 anni fa
parent
commit
f64ae4dd16

+ 6 - 1
Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs

@@ -46,9 +46,14 @@ namespace HyperCube.Areas.Identity.Pages.Account
             {
                 Console.WriteLine($"Adding new confirmed user [{user.UserName}], id: [{userId}] to list!");
                 Models.AccountModel newAcc = new();
+                newAcc.PWDHash = user.PasswordHash;
+                newAcc.UUID = user.Id;
+                newAcc.Name = user.UserName;
+                newAcc.Email = user.Email;
+                newAcc.bsel = 1;
+                newAcc.FillAccount();
                 Models.AccountModel.Loaded.Add(userId, newAcc);
             }
-
             return Page();            
         }
     }

+ 33 - 18
Models/AccountModel.cs

@@ -45,6 +45,7 @@ namespace HyperCube.Models
         {
             return ratingProspector;
         }
+        public Dictionary<int, Notification> notifications = new();
         public Action<int> RolesChanged;
         public byte bsel = 0;
         public byte blockchain_selected
@@ -57,6 +58,16 @@ namespace HyperCube.Models
         }
         public List<Role> Roles = new();
 
+        public async Task SendTestNotification(AccountModel sender)
+        {
+            Notification notification = new(NotificationType.System, "Test from button", "message", UUID, sender.UUID);
+
+            int newid = await notification.Send();
+
+            /// adding only in local collection yet
+            notifications.Add(newid, notification);
+        }
+
         public void AddRole(Role role)
         {
             Roles.Add(role);
@@ -192,29 +203,33 @@ namespace HyperCube.Models
             return 0;
         }
 
-        public static async void InitializeAccounts()
+        public async void FillAccount()
         {
-            Loaded = await MySQLConnector.Instance().SQLSelectASPUsers();
-            Console.WriteLine("InitializeAccounts");
-            foreach (var acc in Loaded)
-            {
-                acc.Value.LoadRoles();
-                var wallets = await MySQLConnector.Instance().SQLSelectComplex($"select * from account_wallets where account_uuid='{acc.Value.UUID}'");
+            LoadRoles();
+            var wallets = await MySQLConnector.Instance().SQLSelectComplex($"select * from account_wallets where account_uuid='{UUID}'");
 
-                if (wallets.Count > 0)
+            if (wallets.Count > 0)
+            {
+                foreach (var wallet in wallets)
                 {
-                    foreach (var wallet in wallets)
-                    {
-                        var bc_id = Convert.ToInt32(wallet["blockchain_id"]);
-                        var wallet_id = Convert.ToString(wallet["uuid"]);
-                        if (bc_id == 0)
-                            acc.Value.eth_address = wallet_id;
-                        else
-                            acc.Value.eth_address1 = wallet_id;
-                        Console.WriteLine($"acc {acc.Value.Name} wallet0 {acc.Value.eth_address} wallet1 {acc.Value.eth_address1}");
-                    }
+                    var bc_id = Convert.ToInt32(wallet["blockchain_id"]);
+                    var wallet_id = Convert.ToString(wallet["uuid"]);
+                    if (bc_id == 0)
+                        eth_address = wallet_id;
+                    else
+                        eth_address1 = wallet_id;
+                    Console.WriteLine($"acc {Name} wallet0 {eth_address} wallet1 {eth_address1}");
                 }
+            }
+        }
 
+        public static async void InitializeAccounts()
+        {
+            Loaded = await MySQLConnector.Instance().SQLSelectASPUsers();
+            Console.WriteLine("InitializeAccounts");
+            foreach (var acc in Loaded.Values)
+            {
+                acc.FillAccount();
             }
         }
 

+ 2 - 0
Models/SmartContract.cs

@@ -159,6 +159,8 @@ namespace HyperCube.Models
                 var tid1 = bc.SubmitTransaction("0xD3ae749f1253b320ea2b90dc235ed72c80447AFF", expert_value.ToString(), verifier_address);
                 var tid2 = bc.SubmitTransaction("0xD3ae749f1253b320ea2b90dc235ed72c80447AFF", initiator_value.ToString(), initiator_address);
                 //init notifications 2DEVS
+                //SendTestNotification(string header, string body, AccountModel receiver, AccountModel sender);
+
                 return "none";
                 var edits_hex = edits.ToString("X64");
                 verifier_address = Blockchain.zerofill(verifier_address, 64, true);

+ 11 - 11
Pages/Blockchains.razor

@@ -84,7 +84,7 @@
     <p><b>@bcMain.url:@bcMain.port </b><br /> <b>Address:</b> @bcMain.address<br /> <b>Balance:</b> @bcMain.balance</p>
     <br>
 
-    <p></p>
+    @*<p></p>
     <p style="visibility:@hidecontr">
         Add smart contract:
     <p><input id="newname" @bind="newname" placeholder="Имя нового контракта" /></p>
@@ -107,14 +107,14 @@
         <p><input id="ts" size="100" @bind="tokenSymbol" name="code" type="text" placeholder="" /></p>
         <p><input id="td" size="100" @bind="tokenDecimals" name="code" type="text" placeholder="" /></p>
         <p><input id="tb" size="100" @bind="tokenBalance" name="code" type="text" placeholder="" /></p>
-    </div>
-    <div>
-        <button @onclick="TransferToken">Transfer</button>
-        <p><input id="tc" size="100" @bind="tokenAmount" name="code" type="text" placeholder="Количество" /></p>
-        <p><input id="tn" size="100" @bind="addressTo" name="code" type="text" placeholder="Адрес получателя" /></p>
-
-    </div>
-    <p>
+    </div>*@
+<div>
+    <button @onclick="TransferToken">Transfer</button>
+    <p><input id="tc" size="100" @bind="tokenContract" name="code" type="text" placeholder="Адрес контракта токена" /></p>
+    <p><input id="tc" size="100" @bind="tokenAmount" name="code" type="text" placeholder="Количество" /></p>
+    <p><input id="tn" size="100" @bind="addressTo" name="code" type="text" placeholder="Адрес получателя" /></p>
+</div>
+    @*<p>
         <select @bind="contrtest">
             <option value="0">[Select Contract]</option>
             @if (Blockchain.loaded.Count > 0)
@@ -140,7 +140,7 @@
     <br>
     @bcMain.id;
     <br />
-    </p>
+    </p>*@
 
     <p>
         <select @bind="accountSelected">
@@ -161,7 +161,7 @@
         <div>Wallet:@myWallet</div>
         <div>Token balance:@balanceHCB</div>
         <br><br>
-        <button @onclick="EstimateGas">EstimateGas</button>
+        @*<button @onclick="EstimateGas">EstimateGas</button>*@
     <p>Export address:</p>
     <button id="btn" @onclick="DloadJSON">Download JSON file</button>
     <button id="btn" @onclick="ExportPrivateKey">Private Key</button>

+ 135 - 141
Pages/ModalNotifications.razor

@@ -1,141 +1,135 @@
-<div class="modal" tabindex="-1" role="dialog" style="display:none" id="@elementid">
-    <div class="modal-container">
-        <div class="modal__body">
-            <div class="modal__body__header">
-                <div class="modal__body__header__info">
-                    <img src="img/user.svg" alt="">
-                    <p>@Title</p>
-                </div>
-            </div>
-            <div class="modal__body__container modal__body__container_noflex" style="vertical-align:top"> 
-                <div class="modal__404__text__box">
-                    @Body
-
-                    <button class="btn_orange" style="margin-bottom: 20px" @onclick="SendTestNotification">Отправить тестовое сообщение этому юзеру</button>
-
-                    <table border="1">
-                        <tr>
-                            <th>Тип</th>
-                            <th>Заголовок</th>
-                            <th>Сообщение</th>
-                            <th>Прочитано</th>
-                            <th>Утверждено</th>
-                            <th>Отклонено</th>
-                        </tr>
-                        @foreach (var n in _notifications)
-                        {
-                            <tr>
-                                <td>@n.Value.NotifiType</td>
-                                <td>@n.Value.Header</td>
-                                <td>@n.Value.Body</td>
-                                <td>
-                                    <input type="checkbox" @bind="n.Value.IsRead" disabled>
-                                    <button @onclick="(() => ReadOnClick(n.Value.ID))">read</button>
-                                </td>
-                                <td>
-                                    <input type="checkbox" @bind="n.Value.IsApproved" disabled>
-                                    <button @onclick="(() => ApproveOnClick(n.Value.ID))">approve</button>
-                                </td>
-                                <td>
-                                    <input type="checkbox" @bind="n.Value.IsRejected" disabled>
-                                    <button @onclick="(() => RejectOnClick(n.Value.ID))">reject</button>
-                                </td>
-                            </tr>
-                        }
-                    </table>
-                </div>
-            </div>
-        </div>
-        <a class="modal_close" style="cursor:pointer" @onclick="@Close">&#10006;</a>
-    </div>
-</div>
-
-@code {
-    @using HyperCube.Models;
-
-    [Inject]
-    public IJSRuntime JsRuntime { get; set; }
-
-    [Parameter]
-    public RenderFragment Title { get; set; }
-
-    [Parameter]
-    public RenderFragment Body { get; set; }
-
-    string message = "";
-    string elementid = "modal_notifications";
-
-    Dictionary<int, Models.Notification> _notifications = new();
-    AccountModel _currentAcc = new();
-
-
-    public void Open(Dictionary<int, Notification> notifications, AccountModel acc)
-    {
-        _notifications = notifications;
-        _currentAcc = acc;
-        JsRuntime.InvokeVoidAsync("OpenModal", elementid);
-    }
-
-    public void Close()
-    {
-        JsRuntime.InvokeVoidAsync("CloseModal", elementid);
-    }
-
-    async Task ReadOnClick(int id)
-    {
-        if (!_notifications[id].IsRead)
-        {
-            _notifications[id].IsRead = true;
-            _notifications[id].DateRead = DateTime.Now;
-        }
-        else
-        {
-            _notifications[id].IsRead = false;
-            _notifications[id].DateRead = null;
-        }
-
-        await _notifications[id].Update();
-    }
-
-    async Task ApproveOnClick(int id)
-    {
-        if (!_notifications[id].IsApproved)
-        {
-            _notifications[id].IsApproved = true;
-            _notifications[id].DateApprove = DateTime.Now;
-        }
-        else
-        {
-            _notifications[id].IsApproved = false;
-            _notifications[id].DateApprove = null;
-        }
-
-        await _notifications[id].Update();
-    }
-
-    async Task RejectOnClick(int id)
-    {
-        if (!_notifications[id].IsRejected)
-        {
-            _notifications[id].IsRejected = true;
-            _notifications[id].DateReject = DateTime.Now;
-        }
-        else
-        {
-            _notifications[id].IsRejected = false;
-            _notifications[id].DateReject = null;
-        }
-
-        await _notifications[id].Update();
-    }
-
-    async Task SendTestNotification()
-    {
-        Notification notification = new(NotificationType.System, "Test from button", "message", _currentAcc.UUID, _currentAcc.UUID);
-
-        int newid = await notification.Send();
-
-        /// adding only in local collection yet
-        _notifications.Add(newid, notification);
-    }
-}
+<div class="modal" tabindex="-1" role="dialog" style="display:none" id="@elementid">
+    <div class="modal-container">
+        <div class="modal__body">
+            <div class="modal__body__header">
+                <div class="modal__body__header__info">
+                    <img src="img/user.svg" alt="">
+                    <p>@Title</p>
+                </div>
+            </div>
+            <div class="modal__body__container modal__body__container_noflex" style="vertical-align:top"> 
+                <div class="modal__404__text__box">
+                    @Body
+
+                    <button class="btn_orange" style="margin-bottom: 20px" @onclick="SendTestNotification">Отправить тестовое сообщение этому юзеру</button>
+
+                    <table border="1">
+                        <tr>
+                            <th>Тип</th>
+                            <th>Заголовок</th>
+                            <th>Сообщение</th>
+                            <th>Прочитано</th>
+                            <th>Утверждено</th>
+                            <th>Отклонено</th>
+                        </tr>
+                        @foreach (var n in _notifications)
+                        {
+                            <tr>
+                                <td>@n.Value.NotifiType</td>
+                                <td>@n.Value.Header</td>
+                                <td>@n.Value.Body</td>
+                                <td>
+                                    <input type="checkbox" @bind="n.Value.IsRead" disabled>
+                                    <button @onclick="(() => ReadOnClick(n.Value.ID))">read</button>
+                                </td>
+                                <td>
+                                    <input type="checkbox" @bind="n.Value.IsApproved" disabled>
+                                    <button @onclick="(() => ApproveOnClick(n.Value.ID))">approve</button>
+                                </td>
+                                <td>
+                                    <input type="checkbox" @bind="n.Value.IsRejected" disabled>
+                                    <button @onclick="(() => RejectOnClick(n.Value.ID))">reject</button>
+                                </td>
+                            </tr>
+                        }
+                    </table>
+                </div>
+            </div>
+        </div>
+        <a class="modal_close" style="cursor:pointer" @onclick="@Close">&#10006;</a>
+    </div>
+</div>
+
+@code {
+    @using HyperCube.Models;
+
+    [Inject]
+    public IJSRuntime JsRuntime { get; set; }
+
+    [Parameter]
+    public RenderFragment Title { get; set; }
+
+    [Parameter]
+    public RenderFragment Body { get; set; }
+
+    string message = "";
+    string elementid = "modal_notifications";
+
+    Dictionary<int, Models.Notification> _notifications = new();
+    AccountModel _currentAcc = new();
+
+    public async Task SendTestNotification()
+    {
+       await _currentAcc.SendTestNotification(_currentAcc);
+    }
+
+    public void Open(Dictionary<int, Notification> notifications, AccountModel acc)
+    {
+        _notifications = acc.notifications;
+        _currentAcc = acc;
+        JsRuntime.InvokeVoidAsync("OpenModal", elementid);
+    }
+
+    public void Close()
+    {
+        JsRuntime.InvokeVoidAsync("CloseModal", elementid);
+    }
+
+    async Task ReadOnClick(int id)
+    {
+        if (!_notifications[id].IsRead)
+        {
+            _notifications[id].IsRead = true;
+            _notifications[id].DateRead = DateTime.Now;
+        }
+        else
+        {
+            _notifications[id].IsRead = false;
+            _notifications[id].DateRead = null;
+        }
+
+        await _notifications[id].Update();
+    }
+
+    async Task ApproveOnClick(int id)
+    {
+        if (!_notifications[id].IsApproved)
+        {
+            _notifications[id].IsApproved = true;
+            _notifications[id].DateApprove = DateTime.Now;
+        }
+        else
+        {
+            _notifications[id].IsApproved = false;
+            _notifications[id].DateApprove = null;
+        }
+
+        await _notifications[id].Update();
+    }
+
+    async Task RejectOnClick(int id)
+    {
+        if (!_notifications[id].IsRejected)
+        {
+            _notifications[id].IsRejected = true;
+            _notifications[id].DateReject = DateTime.Now;
+        }
+        else
+        {
+            _notifications[id].IsRejected = false;
+            _notifications[id].DateReject = null;
+        }
+
+        await _notifications[id].Update();
+    }
+}

+ 4 - 5
Shared/Sidebar.razor.cs

@@ -34,8 +34,7 @@ namespace HyperCube.Shared
 
         AccountModel _currentAccount;
 
-        bool _newNotification = false;
-        Dictionary<int, Notification> _notifications = new();
+        bool _newNotification = false;        
 
         protected override async Task OnInitializedAsync()
         {            
@@ -85,7 +84,7 @@ namespace HyperCube.Shared
             //modalRating.Open();
 
             //tmp
-            modalNotifications.Open(_notifications, _currentAccount);
+            modalNotifications.Open(_currentAccount.notifications, _currentAccount);
         }
 
         void RulesClick()
@@ -112,7 +111,7 @@ namespace HyperCube.Shared
         {
             bool newNotifications = false;
             Notification notification;
-            _notifications.Clear();
+            _currentAccount.notifications.Clear();
 
             var notifications = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM notifications WHERE recipientid='{_currentAccount.UUID}'");
             if (notifications.Count > 0)
@@ -132,7 +131,7 @@ namespace HyperCube.Shared
                     };
                     Console.WriteLine($"add notification. id: {notification.ID}, header: {notification.Header}, body: {notification.Body}");
 
-                    _notifications.Add(notification.ID, notification);
+                    _currentAccount.notifications.Add(notification.ID, notification);
 
                     if (!notification.IsRead)
                         newNotifications = true;