From b45bfd76d66966671120f3ebb065a4b451cd2616 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Tue, 6 Jun 2023 17:44:04 +1000 Subject: [PATCH] main: account login finished --- FireWallet/FireWallet.csproj | 15 +++ FireWallet/MainForm.Designer.cs | 33 +++++- FireWallet/MainForm.cs | 72 ++++++++++-- FireWallet/Properties/Resources.Designer.cs | 63 ++++++++++ FireWallet/Properties/Resources.resx | 120 ++++++++++++++++++++ 5 files changed, 287 insertions(+), 16 deletions(-) create mode 100644 FireWallet/Properties/Resources.Designer.cs create mode 100644 FireWallet/Properties/Resources.resx diff --git a/FireWallet/FireWallet.csproj b/FireWallet/FireWallet.csproj index bfb233c..8703340 100644 --- a/FireWallet/FireWallet.csproj +++ b/FireWallet/FireWallet.csproj @@ -12,4 +12,19 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/FireWallet/MainForm.Designer.cs b/FireWallet/MainForm.Designer.cs index 079e450..57fa8bc 100644 --- a/FireWallet/MainForm.Designer.cs +++ b/FireWallet/MainForm.Designer.cs @@ -32,6 +32,8 @@ statusStripmain = new StatusStrip(); toolStripStatusLabelNetwork = new ToolStripStatusLabel(); toolStripStatusLabelstatus = new ToolStripStatusLabel(); + toolStripStatusLabelaccount = new ToolStripStatusLabel(); + toolStripSplitButtonlogout = new ToolStripSplitButton(); timerNodeStatus = new System.Windows.Forms.Timer(components); panelaccount = new Panel(); groupBoxaccount = new GroupBox(); @@ -50,7 +52,7 @@ // statusStripmain // statusStripmain.Dock = DockStyle.Top; - statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus }); + statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus, toolStripStatusLabelaccount, toolStripSplitButtonlogout }); statusStripmain.Location = new Point(0, 0); statusStripmain.Name = "statusStripmain"; statusStripmain.Size = new Size(1074, 22); @@ -72,6 +74,24 @@ toolStripStatusLabelstatus.Size = new Size(126, 17); toolStripStatusLabelstatus.Text = "Status: Not Connected"; // + // toolStripStatusLabelaccount + // + toolStripStatusLabelaccount.Margin = new Padding(0, 3, 50, 2); + toolStripStatusLabelaccount.Name = "toolStripStatusLabelaccount"; + toolStripStatusLabelaccount.Size = new Size(55, 17); + toolStripStatusLabelaccount.Text = "Account:"; + // + // toolStripSplitButtonlogout + // + toolStripSplitButtonlogout.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripSplitButtonlogout.DropDownButtonWidth = 0; + toolStripSplitButtonlogout.ImageTransparentColor = Color.Magenta; + toolStripSplitButtonlogout.Name = "toolStripSplitButtonlogout"; + toolStripSplitButtonlogout.Size = new Size(53, 20); + toolStripSplitButtonlogout.Text = "Log out"; + toolStripSplitButtonlogout.Visible = false; + toolStripSplitButtonlogout.ButtonClick += toolStripSplitButtonlogout_ButtonClickAsync; + // // timerNodeStatus // timerNodeStatus.Enabled = true; @@ -115,14 +135,16 @@ label1.TabIndex = 7; label1.Text = "Please Login to your account"; // - // comboBoxusername + // comboBoxaccount // + comboBoxaccount.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxaccount.FlatStyle = FlatStyle.Popup; comboBoxaccount.FormattingEnabled = true; comboBoxaccount.Location = new Point(97, 67); - comboBoxaccount.Name = "comboBoxusername"; + comboBoxaccount.Name = "comboBoxaccount"; comboBoxaccount.Size = new Size(190, 23); comboBoxaccount.TabIndex = 6; + comboBoxaccount.DropDownClosed += comboBoxaccount_DropDownClosed; // // textBoxaccountpassword // @@ -131,6 +153,7 @@ textBoxaccountpassword.Size = new Size(190, 23); textBoxaccountpassword.TabIndex = 5; textBoxaccountpassword.UseSystemPasswordChar = true; + textBoxaccountpassword.KeyDown += textBoxaccountpassword_KeyDown; // // buttonaccountlogin // @@ -198,7 +221,7 @@ private StatusStrip statusStripmain; private ToolStripStatusLabel toolStripStatusLabelNetwork; - private ToolStripStatusLabel toolStripStatusLabelstatus; + private ToolStripStatusLabel toolStripStatusLabelaccount; private System.Windows.Forms.Timer timerNodeStatus; private Panel panelaccount; private Button buttonaccountlogin; @@ -209,5 +232,7 @@ private Label label1; private ComboBox comboBoxaccount; private TextBox textBoxaccountpassword; + private ToolStripStatusLabel toolStripStatusLabelstatus; + private ToolStripSplitButton toolStripSplitButtonlogout; } } \ No newline at end of file diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index 55dc657..fb045b0 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -335,14 +335,8 @@ namespace FireWallet string content = "{\"passphrase\": \"" + password + "\",\"timeout\": 60}"; string APIresponse = await APIPost(path, true, content); - - if (APIresponse.Contains("true")) - { - MessageBox.Show(APIresponse); - AddLog("Login success"); - return true; - } - else + + if (!APIresponse.Contains("true")) { AddLog("Login failed"); NotifyForm notifyForm = new NotifyForm("Login Failed\nMake sure your password is correct"); @@ -351,9 +345,21 @@ namespace FireWallet return false; } + path = ""; + content = "{\"method\": \"selectwallet\",\"params\":[ \"" + account + "\"]}"; + APIresponse = await APIPost(path, true, content); + if (!APIresponse.Contains("\"error\":null")) + { + AddLog("Wallet selection failed"); + NotifyForm notifyForm = new NotifyForm("Wallet selection failed\n" + APIresponse); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + return false; + } + AddLog("Login successful"); - return false; + return true; } #endregion @@ -422,8 +428,9 @@ namespace FireWallet // Send request HttpResponseMessage resp = await httpClient.SendAsync(req); - try { - resp.EnsureSuccessStatusCode(); + try + { + resp.EnsureSuccessStatusCode(); } catch { @@ -469,7 +476,48 @@ namespace FireWallet { account = comboBoxaccount.Text; password = textBoxaccountpassword.Text; - await Login(); + bool loggedin = await Login(); + if (loggedin) + { + toolStripStatusLabelaccount.Text = "Account: " + account; + textBoxaccountpassword.Text = ""; + panelaccount.Visible = false; + toolStripSplitButtonlogout.Visible = true; + } + } + + private void textBoxaccountpassword_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyValue == 13) + { + LoginClick(sender, e); + } + } + + private void comboBoxaccount_DropDownClosed(object sender, EventArgs e) + { + textBoxaccountpassword.Focus(); + } + + private async void toolStripSplitButtonlogout_ButtonClickAsync(object sender, EventArgs e) + { + toolStripSplitButtonlogout.Visible = false; + string path = "wallet/" + account + "/lock"; + string content = ""; + string APIresponse = await APIPost(path, true, content); + if (!APIresponse.Contains("true")) + { + AddLog("Logout failed"); + NotifyForm notifyForm = new NotifyForm("Logout Failed\n" + APIresponse); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + panelaccount.Visible = true; + return; + } + AddLog("Logout successful"); + panelaccount.Visible = true; + toolStripStatusLabelaccount.Text = "Account: Not Logged In"; + } } } \ No newline at end of file diff --git a/FireWallet/Properties/Resources.Designer.cs b/FireWallet/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6b7922f --- /dev/null +++ b/FireWallet/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FireWallet.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FireWallet.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/FireWallet/Properties/Resources.resx b/FireWallet/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FireWallet/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file