main: Added login prompt

This commit is contained in:
Nathan Woodburn 2023-06-06 16:44:58 +10:00
parent ea95ad2fc6
commit 1e10f4763f
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 121 additions and 40 deletions

View File

@ -8,4 +8,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project> </Project>

View File

@ -37,11 +37,11 @@
groupBoxaccount = new GroupBox(); groupBoxaccount = new GroupBox();
label1 = new Label(); label1 = new Label();
comboBoxusername = new ComboBox(); comboBoxusername = new ComboBox();
textBox1 = new TextBox(); textBoxaccountpassword = new TextBox();
button2 = new Button(); buttonaccountlogin = new Button();
labelaccountpassword = new Label(); labelaccountpassword = new Label();
labelaccountusername = new Label(); labelaccountusername = new Label();
button1 = new Button(); buttonaccountnew = new Button();
statusStripmain.SuspendLayout(); statusStripmain.SuspendLayout();
panelaccount.SuspendLayout(); panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout(); groupBoxaccount.SuspendLayout();
@ -92,11 +92,11 @@
// //
groupBoxaccount.Controls.Add(label1); groupBoxaccount.Controls.Add(label1);
groupBoxaccount.Controls.Add(comboBoxusername); groupBoxaccount.Controls.Add(comboBoxusername);
groupBoxaccount.Controls.Add(textBox1); groupBoxaccount.Controls.Add(textBoxaccountpassword);
groupBoxaccount.Controls.Add(button2); groupBoxaccount.Controls.Add(buttonaccountlogin);
groupBoxaccount.Controls.Add(labelaccountpassword); groupBoxaccount.Controls.Add(labelaccountpassword);
groupBoxaccount.Controls.Add(labelaccountusername); groupBoxaccount.Controls.Add(labelaccountusername);
groupBoxaccount.Controls.Add(button1); groupBoxaccount.Controls.Add(buttonaccountnew);
groupBoxaccount.FlatStyle = FlatStyle.Popup; groupBoxaccount.FlatStyle = FlatStyle.Popup;
groupBoxaccount.Location = new Point(458, 155); groupBoxaccount.Location = new Point(458, 155);
groupBoxaccount.Name = "groupBoxaccount"; groupBoxaccount.Name = "groupBoxaccount";
@ -124,23 +124,23 @@
comboBoxusername.Size = new Size(190, 23); comboBoxusername.Size = new Size(190, 23);
comboBoxusername.TabIndex = 6; comboBoxusername.TabIndex = 6;
// //
// textBox1 // textBoxaccountpassword
// //
textBox1.Location = new Point(97, 101); textBoxaccountpassword.Location = new Point(97, 101);
textBox1.Name = "textBox1"; textBoxaccountpassword.Name = "textBoxaccountpassword";
textBox1.Size = new Size(190, 23); textBoxaccountpassword.Size = new Size(190, 23);
textBox1.TabIndex = 5; textBoxaccountpassword.TabIndex = 5;
textBox1.UseSystemPasswordChar = true; textBoxaccountpassword.UseSystemPasswordChar = true;
// //
// button2 // buttonaccountlogin
// //
button2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonaccountlogin.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button2.Location = new Point(188, 164); buttonaccountlogin.Location = new Point(188, 164);
button2.Name = "button2"; buttonaccountlogin.Name = "buttonaccountlogin";
button2.Size = new Size(99, 41); buttonaccountlogin.Size = new Size(99, 41);
button2.TabIndex = 3; buttonaccountlogin.TabIndex = 3;
button2.Text = "button2"; buttonaccountlogin.Text = "Login";
button2.UseVisualStyleBackColor = true; buttonaccountlogin.UseVisualStyleBackColor = true;
// //
// labelaccountpassword // labelaccountpassword
// //
@ -162,15 +162,15 @@
labelaccountusername.TabIndex = 1; labelaccountusername.TabIndex = 1;
labelaccountusername.Text = "Account:"; labelaccountusername.Text = "Account:";
// //
// button1 // buttonaccountnew
// //
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonaccountnew.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button1.Location = new Point(6, 164); buttonaccountnew.Location = new Point(12, 164);
button1.Name = "button1"; buttonaccountnew.Name = "buttonaccountnew";
button1.Size = new Size(99, 41); buttonaccountnew.Size = new Size(99, 41);
button1.TabIndex = 2; buttonaccountnew.TabIndex = 2;
button1.Text = "button1"; buttonaccountnew.Text = "New";
button1.UseVisualStyleBackColor = true; buttonaccountnew.UseVisualStyleBackColor = true;
// //
// MainForm // MainForm
// //
@ -200,13 +200,13 @@
private ToolStripStatusLabel toolStripStatusLabelstatus; private ToolStripStatusLabel toolStripStatusLabelstatus;
private System.Windows.Forms.Timer timerNodeStatus; private System.Windows.Forms.Timer timerNodeStatus;
private Panel panelaccount; private Panel panelaccount;
private Button button2; private Button buttonaccountlogin;
private Button button1; private Button buttonaccountnew;
private Label labelaccountusername; private Label labelaccountusername;
private Label labelaccountpassword; private Label labelaccountpassword;
private GroupBox groupBoxaccount; private GroupBox groupBoxaccount;
private Label label1; private Label label1;
private ComboBox comboBoxusername; private ComboBox comboBoxusername;
private TextBox textBox1; private TextBox textBoxaccountpassword;
} }
} }

View File

@ -1,4 +1,5 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Newtonsoft.Json.Linq;
namespace FireWallet namespace FireWallet
{ {
@ -26,6 +27,9 @@ namespace FireWallet
AddLog("Finished loading"); AddLog("Finished loading");
ResizeForm(); ResizeForm();
// Prompt for login
GetAccounts();
} }
private void MainForm_Closing(object sender, FormClosingEventArgs e) private void MainForm_Closing(object sender, FormClosingEventArgs e)
{ {
@ -283,12 +287,55 @@ namespace FireWallet
[DllImport("user32.dll")] [DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
} }
private void Form1_Resize(object sender, EventArgs e)
{
ResizeForm();
}
private void ResizeForm()
{
groupBoxaccount.Left = (this.ClientSize.Width - groupBoxaccount.Width) / 2;
groupBoxaccount.Top = (this.ClientSize.Height - groupBoxaccount.Height) / 2;
}
#endregion #endregion
#region Accounts
private async void GetAccounts()
{
await APIGet("wallet", true);
comboBoxusername.Items.Clear();
if (APIresponse != "Error")
{
JArray jArray = JArray.Parse(APIresponse);
foreach (string account in jArray)
{
comboBoxusername.Items.Add(account);
}
if (comboBoxusername.Items.Count > 0)
{
comboBoxusername.SelectedIndex = 0;
}
else
{
comboBoxusername.Items.Add("No accounts found");
comboBoxusername.Enabled = false;
}
}
else
{
comboBoxusername.Items.Add("No accounts found");
comboBoxusername.Enabled = false;
}
}
#endregion
private void timerNodeStatus_Tick(object sender, EventArgs e) private void timerNodeStatus_Tick(object sender, EventArgs e)
{ {
NodeStatus(); NodeStatus();
} }
#region API
string APIresponse;
private async void NodeStatus() private async void NodeStatus()
{ {
// This will curl the below URL and return the result // This will curl the below URL and return the result
@ -326,15 +373,44 @@ namespace FireWallet
toolStripStatusLabelstatus.Text = "Status: Node Not Connected"; toolStripStatusLabelstatus.Text = "Status: Node Not Connected";
} }
} }
private async Task APIGet(string path, bool wallet)
{
// This will curl the below URL and return the result
//curl http://x:api-key@127.0.0.1:12039/wallet/$id/account
private void Form1_Resize(object sender, EventArgs e) string key = nodeSettings["Key"];
string ip = nodeSettings["IP"];
string port = "1203";
if (Network == 1)
{ {
ResizeForm(); port = "1303";
} }
private void ResizeForm() if (wallet) port = port + "9";
else port = port + "7";
// Create HTTP client
HttpClient httpClient = new HttpClient();
try
{ {
groupBoxaccount.Left = (this.ClientSize.Width - groupBoxaccount.Width) / 2; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://" + ip + ":" + port + "/" + path);
groupBoxaccount.Top = (this.ClientSize.Height - groupBoxaccount.Height) / 2; // Add API key to header
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + key)));
// Send request and log response
HttpResponseMessage response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
APIresponse = await response.Content.ReadAsStringAsync();
}
// Log errors to log textbox
catch (Exception ex)
{
AddLog("Error: " + ex.Message);
APIresponse = "Error";
} }
} }
#endregion
}
} }

View File

@ -1 +1,2 @@
# FireWallet # FireWallet
Experimental wallet for Handshake chain