mirror of
https://git.alee14.me/shiftos-archive/ShiftOS_TheReturn.git
synced 2025-01-22 18:02:16 +00:00
unite registration
This commit is contained in:
parent
354b65cc54
commit
aec0eff818
4 changed files with 141 additions and 14 deletions
|
@ -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);
|
||||
|
|
37
ShiftOS.WinForms/UniteSignupDialog.Designer.cs
generated
37
ShiftOS.WinForms/UniteSignupDialog.Designer.cs
generated
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,14 +298,7 @@ namespace ShiftOS.Engine
|
|||
Console.Write("{SE_SAVING}... ");
|
||||
if (SaveSystem.CurrentSave != null)
|
||||
{
|
||||
string username = CurrentSave.Username;
|
||||
string password = CurrentSave.Password;
|
||||
|
||||
Utils.WriteAllText(Paths.GetPath("user.dat"), $@"{{
|
||||
username: ""{username}"",
|
||||
password: ""{password}""
|
||||
}}");
|
||||
|
||||
Utils.WriteAllText(Paths.GetPath("user.dat"), CurrentSave.UniteAuthToken);
|
||||
ServerManager.SendMessage("mud_save", JsonConvert.SerializeObject(CurrentSave, Formatting.Indented));
|
||||
}
|
||||
if (!Shiftorium.Silent)
|
||||
|
|
Loading…
Reference in a new issue