mirror of
https://github.com/Nathanwoodburn/FireWallet.git
synced 2024-12-27 00:08:15 +11:00
main: Added login prompt
This commit is contained in:
parent
ea95ad2fc6
commit
1e10f4763f
@ -8,4 +8,8 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
62
FireWallet/MainForm.Designer.cs
generated
62
FireWallet/MainForm.Designer.cs
generated
@ -37,11 +37,11 @@
|
||||
groupBoxaccount = new GroupBox();
|
||||
label1 = new Label();
|
||||
comboBoxusername = new ComboBox();
|
||||
textBox1 = new TextBox();
|
||||
button2 = new Button();
|
||||
textBoxaccountpassword = new TextBox();
|
||||
buttonaccountlogin = new Button();
|
||||
labelaccountpassword = new Label();
|
||||
labelaccountusername = new Label();
|
||||
button1 = new Button();
|
||||
buttonaccountnew = new Button();
|
||||
statusStripmain.SuspendLayout();
|
||||
panelaccount.SuspendLayout();
|
||||
groupBoxaccount.SuspendLayout();
|
||||
@ -92,11 +92,11 @@
|
||||
//
|
||||
groupBoxaccount.Controls.Add(label1);
|
||||
groupBoxaccount.Controls.Add(comboBoxusername);
|
||||
groupBoxaccount.Controls.Add(textBox1);
|
||||
groupBoxaccount.Controls.Add(button2);
|
||||
groupBoxaccount.Controls.Add(textBoxaccountpassword);
|
||||
groupBoxaccount.Controls.Add(buttonaccountlogin);
|
||||
groupBoxaccount.Controls.Add(labelaccountpassword);
|
||||
groupBoxaccount.Controls.Add(labelaccountusername);
|
||||
groupBoxaccount.Controls.Add(button1);
|
||||
groupBoxaccount.Controls.Add(buttonaccountnew);
|
||||
groupBoxaccount.FlatStyle = FlatStyle.Popup;
|
||||
groupBoxaccount.Location = new Point(458, 155);
|
||||
groupBoxaccount.Name = "groupBoxaccount";
|
||||
@ -124,23 +124,23 @@
|
||||
comboBoxusername.Size = new Size(190, 23);
|
||||
comboBoxusername.TabIndex = 6;
|
||||
//
|
||||
// textBox1
|
||||
// textBoxaccountpassword
|
||||
//
|
||||
textBox1.Location = new Point(97, 101);
|
||||
textBox1.Name = "textBox1";
|
||||
textBox1.Size = new Size(190, 23);
|
||||
textBox1.TabIndex = 5;
|
||||
textBox1.UseSystemPasswordChar = true;
|
||||
textBoxaccountpassword.Location = new Point(97, 101);
|
||||
textBoxaccountpassword.Name = "textBoxaccountpassword";
|
||||
textBoxaccountpassword.Size = new Size(190, 23);
|
||||
textBoxaccountpassword.TabIndex = 5;
|
||||
textBoxaccountpassword.UseSystemPasswordChar = true;
|
||||
//
|
||||
// button2
|
||||
// buttonaccountlogin
|
||||
//
|
||||
button2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
button2.Location = new Point(188, 164);
|
||||
button2.Name = "button2";
|
||||
button2.Size = new Size(99, 41);
|
||||
button2.TabIndex = 3;
|
||||
button2.Text = "button2";
|
||||
button2.UseVisualStyleBackColor = true;
|
||||
buttonaccountlogin.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonaccountlogin.Location = new Point(188, 164);
|
||||
buttonaccountlogin.Name = "buttonaccountlogin";
|
||||
buttonaccountlogin.Size = new Size(99, 41);
|
||||
buttonaccountlogin.TabIndex = 3;
|
||||
buttonaccountlogin.Text = "Login";
|
||||
buttonaccountlogin.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelaccountpassword
|
||||
//
|
||||
@ -162,15 +162,15 @@
|
||||
labelaccountusername.TabIndex = 1;
|
||||
labelaccountusername.Text = "Account:";
|
||||
//
|
||||
// button1
|
||||
// buttonaccountnew
|
||||
//
|
||||
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
button1.Location = new Point(6, 164);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(99, 41);
|
||||
button1.TabIndex = 2;
|
||||
button1.Text = "button1";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
buttonaccountnew.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonaccountnew.Location = new Point(12, 164);
|
||||
buttonaccountnew.Name = "buttonaccountnew";
|
||||
buttonaccountnew.Size = new Size(99, 41);
|
||||
buttonaccountnew.TabIndex = 2;
|
||||
buttonaccountnew.Text = "New";
|
||||
buttonaccountnew.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
@ -200,13 +200,13 @@
|
||||
private ToolStripStatusLabel toolStripStatusLabelstatus;
|
||||
private System.Windows.Forms.Timer timerNodeStatus;
|
||||
private Panel panelaccount;
|
||||
private Button button2;
|
||||
private Button button1;
|
||||
private Button buttonaccountlogin;
|
||||
private Button buttonaccountnew;
|
||||
private Label labelaccountusername;
|
||||
private Label labelaccountpassword;
|
||||
private GroupBox groupBoxaccount;
|
||||
private Label label1;
|
||||
private ComboBox comboBoxusername;
|
||||
private TextBox textBox1;
|
||||
private TextBox textBoxaccountpassword;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace FireWallet
|
||||
{
|
||||
@ -26,6 +27,9 @@ namespace FireWallet
|
||||
|
||||
AddLog("Finished loading");
|
||||
ResizeForm();
|
||||
|
||||
// Prompt for login
|
||||
GetAccounts();
|
||||
}
|
||||
private void MainForm_Closing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
@ -283,12 +287,55 @@ namespace FireWallet
|
||||
[DllImport("user32.dll")]
|
||||
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
|
||||
#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)
|
||||
{
|
||||
NodeStatus();
|
||||
}
|
||||
#region API
|
||||
string APIresponse;
|
||||
private async void NodeStatus()
|
||||
{
|
||||
// This will curl the below URL and return the result
|
||||
@ -326,15 +373,44 @@ namespace FireWallet
|
||||
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)
|
||||
{
|
||||
ResizeForm();
|
||||
}
|
||||
private void ResizeForm()
|
||||
{
|
||||
groupBoxaccount.Left = (this.ClientSize.Width - groupBoxaccount.Width) / 2;
|
||||
groupBoxaccount.Top = (this.ClientSize.Height - groupBoxaccount.Height) / 2;
|
||||
string key = nodeSettings["Key"];
|
||||
string ip = nodeSettings["IP"];
|
||||
|
||||
string port = "1203";
|
||||
if (Network == 1)
|
||||
{
|
||||
port = "1303";
|
||||
}
|
||||
if (wallet) port = port + "9";
|
||||
else port = port + "7";
|
||||
|
||||
|
||||
// Create HTTP client
|
||||
HttpClient httpClient = new HttpClient();
|
||||
|
||||
try
|
||||
{
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://" + ip + ":" + port + "/" + path);
|
||||
// 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user