aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.WinForms')
-rw-r--r--ShiftOS.WinForms/Oobe.cs16
-rw-r--r--ShiftOS.WinForms/UniteSignupDialog.Designer.cs37
-rw-r--r--ShiftOS.WinForms/UniteSignupDialog.cs93
3 files changed, 140 insertions, 6 deletions
diff --git a/ShiftOS.WinForms/Oobe.cs b/ShiftOS.WinForms/Oobe.cs
index 35efca4..245d13e 100644
--- a/ShiftOS.WinForms/Oobe.cs
+++ b/ShiftOS.WinForms/Oobe.cs
@@ -263,6 +263,22 @@ You must join the digital society, rise up the ranks, and save us.
{
var signupDialog = new UniteSignupDialog((token) =>
{
+ ServerMessageReceived smr = null;
+ smr = (msg) =>
+ {
+ ServerManager.MessageReceived -= smr;
+ if (msg.Name == "mud_savefile")
+ {
+ SaveSystem.CurrentSave = JsonConvert.DeserializeObject<Save>(msg.Contents);
+ SaveSystem.SaveGame();
+ }
+ else
+ {
+ LinkSaveFile(token);
+ }
+ };
+ ServerManager.MessageReceived += smr;
+ ServerManager.SendMessage("mud_token_login", token);
});
AppearanceManager.SetupDialog(signupDialog);
diff --git a/ShiftOS.WinForms/UniteSignupDialog.Designer.cs b/ShiftOS.WinForms/UniteSignupDialog.Designer.cs
index 752f5c0..a1509d7 100644
--- a/ShiftOS.WinForms/UniteSignupDialog.Designer.cs
+++ b/ShiftOS.WinForms/UniteSignupDialog.Designer.cs
@@ -40,17 +40,20 @@
this.txtdisplay = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
+ this.txtsysname = new System.Windows.Forms.TextBox();
+ this.label7 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnlogin
//
this.btnlogin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.btnlogin.Location = new System.Drawing.Point(462, 407);
+ this.btnlogin.Location = new System.Drawing.Point(462, 479);
this.btnlogin.Name = "btnlogin";
this.btnlogin.Size = new System.Drawing.Size(75, 23);
this.btnlogin.TabIndex = 11;
this.btnlogin.Text = "Submit";
this.btnlogin.UseVisualStyleBackColor = true;
+ this.btnlogin.Click += new System.EventHandler(this.btnlogin_Click);
//
// txtpassword
//
@@ -94,10 +97,10 @@
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 36);
this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(84, 13);
+ this.label1.Size = new System.Drawing.Size(120, 13);
this.label1.TabIndex = 6;
this.label1.Tag = "header2";
- this.label1.Text = "Login to ShiftOS";
+ this.label1.Text = "Create ShiftOS Account";
//
// txtconfirm
//
@@ -141,16 +144,36 @@
this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
- this.label6.Location = new System.Drawing.Point(20, 251);
+ this.label6.Location = new System.Drawing.Point(20, 267);
this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(517, 153);
+ this.label6.Size = new System.Drawing.Size(517, 209);
this.label6.TabIndex = 16;
this.label6.Text = resources.GetString("label6.Text");
//
+ // txtsysname
+ //
+ this.txtsysname.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.txtsysname.Location = new System.Drawing.Point(113, 223);
+ this.txtsysname.Name = "txtsysname";
+ this.txtsysname.Size = new System.Drawing.Size(424, 20);
+ this.txtsysname.TabIndex = 18;
+ //
+ // label7
+ //
+ this.label7.AutoSize = true;
+ this.label7.Location = new System.Drawing.Point(17, 226);
+ this.label7.Name = "label7";
+ this.label7.Size = new System.Drawing.Size(73, 13);
+ this.label7.TabIndex = 17;
+ this.label7.Text = "System name:";
+ //
// UniteSignupDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.txtsysname);
+ this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.txtdisplay);
this.Controls.Add(this.label5);
@@ -163,7 +186,7 @@
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "UniteSignupDialog";
- this.Size = new System.Drawing.Size(555, 447);
+ this.Size = new System.Drawing.Size(555, 519);
this.ResumeLayout(false);
this.PerformLayout();
@@ -182,5 +205,7 @@
private System.Windows.Forms.TextBox txtdisplay;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.TextBox txtsysname;
+ private System.Windows.Forms.Label label7;
}
}
diff --git a/ShiftOS.WinForms/UniteSignupDialog.cs b/ShiftOS.WinForms/UniteSignupDialog.cs
index 2f20d9f..a46a9b0 100644
--- a/ShiftOS.WinForms/UniteSignupDialog.cs
+++ b/ShiftOS.WinForms/UniteSignupDialog.cs
@@ -8,6 +8,8 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine;
+using Newtonsoft.Json;
+using System.Net;
namespace ShiftOS.WinForms
{
@@ -39,5 +41,96 @@ namespace ShiftOS.WinForms
public void OnUpgrade()
{
}
+
+ private void btnlogin_Click(object sender, EventArgs e)
+ {
+ string u = txtusername.Text;
+ string p = txtpassword.Text;
+
+ if (string.IsNullOrWhiteSpace(u))
+ {
+ Infobox.Show("Please enter a username.", "You must enter a proper email address.");
+ return;
+ }
+
+ if (string.IsNullOrWhiteSpace(p))
+ {
+ Infobox.Show("Please enter a password.", "You must enter a valid password.");
+ return;
+ }
+
+ if(p != txtconfirm.Text)
+ {
+ Infobox.Show("Passwords don't match.", "The \"Password\" and \"Confirm\" boxes must match.");
+ return;
+ }
+
+ if (string.IsNullOrWhiteSpace(txtdisplay.Text))
+ {
+ Infobox.Show("Empty display name", "Please choose a proper display name.");
+ return;
+ }
+
+ if (string.IsNullOrWhiteSpace(txtsysname.Text))
+ {
+ Infobox.Show("Empty system name", "Please name your computer!");
+ return;
+ }
+
+ if(p.Length < 7)
+ {
+ Infobox.Show("Password error", "Your password must have at least 7 characters.");
+ return;
+ }
+
+ if (!(p.Any(char.IsUpper) &&
+ p.Any(char.IsLower) &&
+ p.Any(char.IsDigit)))
+ {
+ Infobox.Show("Password error", "Your password must contain at least one uppercase, lowercase, digit and symbol character.");
+ return;
+ }
+
+ if (!u.Contains("@"))
+ {
+ Infobox.Show("Valid email required.", "You must specify a valid email address.");
+ return;
+ }
+
+ try
+ {
+ var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Register?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4&displayname=" + txtdisplay.Text + "&sysname=" + txtsysname.Text);
+ string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{u}:{p}"));
+ webrequest.Headers.Add("Authentication: Basic " + base64);
+ var response = webrequest.GetResponse();
+ var str = response.GetResponseStream();
+ var reader = new System.IO.StreamReader(str);
+ string result = reader.ReadToEnd();
+ if (result.StartsWith("{"))
+ {
+ var exc = JsonConvert.DeserializeObject<Exception>(result);
+ Infobox.Show("Error", exc.Message);
+ return;
+ }
+ reader.Close();
+ str.Close();
+ str.Dispose();
+ response.Dispose();
+ Callback?.Invoke(result);
+ AppearanceManager.Close(this);
+ }
+#if DEBUG
+ catch (Exception ex)
+ {
+ Infobox.Show("Error", ex.ToString());
+ }
+#else
+ catch
+ {
+ Infobox.Show("Login failed.", "The login attempt failed due to an incorrect username and password pair.");
+ }
+#endif
+
+ }
}
}