diff options
Diffstat (limited to 'ShiftOS.WinForms')
| -rw-r--r-- | ShiftOS.WinForms/Applications/Dialog.cs | 7 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Oobe.cs | 115 | ||||
| -rw-r--r-- | ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 | ||||
| -rw-r--r-- | ShiftOS.WinForms/UniteLoginDialog.Designer.cs | 123 | ||||
| -rw-r--r-- | ShiftOS.WinForms/UniteLoginDialog.cs | 90 | ||||
| -rw-r--r-- | ShiftOS.WinForms/UniteLoginDialog.resx | 120 |
6 files changed, 422 insertions, 42 deletions
diff --git a/ShiftOS.WinForms/Applications/Dialog.cs b/ShiftOS.WinForms/Applications/Dialog.cs index 6e358e6..2abc705 100644 --- a/ShiftOS.WinForms/Applications/Dialog.cs +++ b/ShiftOS.WinForms/Applications/Dialog.cs @@ -69,7 +69,7 @@ namespace ShiftOS.WinForms.Applications { } - internal void OpenInternal(string title, string msg) + internal void OpenInternal(string title, string msg, Action c) { Title = title; AppearanceManager.SetupDialog(this); @@ -80,7 +80,7 @@ namespace ShiftOS.WinForms.Applications btnok.Click += (o, a) => { AppearanceManager.Close(this); - OpenCallback?.Invoke(); + c?.Invoke(); }; } @@ -89,8 +89,7 @@ namespace ShiftOS.WinForms.Applications public void Open(string title, string msg, Action c = null) { - OpenCallback = c; - new Dialog().OpenInternal(title, msg); + new Dialog().OpenInternal(title, msg, c); } public void PromptTextInternal(string title, string message, Action<string> callback, bool isPassword) diff --git a/ShiftOS.WinForms/Oobe.cs b/ShiftOS.WinForms/Oobe.cs index 309495d..6339588 100644 --- a/ShiftOS.WinForms/Oobe.cs +++ b/ShiftOS.WinForms/Oobe.cs @@ -36,6 +36,7 @@ using Newtonsoft.Json; using ShiftOS.Engine; using ShiftOS.Objects; using ShiftOS.Objects.ShiftFS; +using ShiftOS.Unite; using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms @@ -219,55 +220,93 @@ You must join the digital society, rise up the ranks, and save us. t.Start(); } + public void PerformUniteLogin() + { + + } + public void PromptForLogin() { - ServerMessageReceived MessageReceived = null; - MessageReceived = (msg) => + Infobox.Show("Login", "Since the last time you've played ShiftOS, some changes have been made to the login system. You must now login using your website credentials.", () => { - if(msg.Name == "mud_savefile") + Infobox.PromptYesNo("Website account", "Do you have an account at http://getshiftos.ml?", (hasAccount) => { - SaveSystem.CurrentSave = JsonConvert.DeserializeObject<Save>(msg.Contents); - SaveSystem.SaveGame(); - Application.Restart(); - } - else if(msg.Name == "mud_notfound") - { - ServerManager.MessageReceived -= MessageReceived; - - PromptForLogin(); - } - }; - ServerManager.MessageReceived += MessageReceived; - Infobox.PromptYesNo("Login", "You are missing a digital society authentication link. Would you like to generate a new link with an existing account? Choosing \"No\" will restart the session in the out-of-box experience.", (result)=> + if(hasAccount == true) + { + var loginDialog = new UniteLoginDialog((success)=> + { + string token = success; + var uClient = new UniteClient("http://getshiftos.ml", token); + Infobox.Show("Welcome to ShiftOS.", $"Hello, {uClient.GetDisplayName()}! We've signed you into your account. We'll now try to link your ShiftOS account with your save file.", () => + { + 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(loginDialog); + } + }); + }); + } + + public void LinkSaveFile(string token) + { + Infobox.PromptText("Enter username", "Please enter the username you used for your save file before these changes.", (cuname) => { - if (result == true) + Infobox.PromptText("Enter password", "Now, please enter the corresponding password.", (cpass) => { - Infobox.PromptText("Login", "Please enter your digital society username.", (uname) => + ServerMessageReceived nsmr = null; + nsmr = (nmsg) => { - Infobox.PromptText("Login", "Please enter your password.", (pword) => + ServerManager.MessageReceived -= nsmr; + if (nmsg.Name == "mud_savefile") { - ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new + var save = JsonConvert.DeserializeObject<Save>(nmsg.Contents); + save.UniteAuthToken = token; + Infobox.Show("That'll do it.", "Your save has been linked up! Next time you log into the ShiftOS site, your Codepoints should show on your profile. There's just a few more things we have to do.", () => { - username = uname, - password = pword - })); - }, true); - }); - } - else - { - //restart in OOBE - if (Objects.ShiftFS.Utils.FileExists(Paths.GetPath("user.dat"))) + SaveSystem.CurrentSave = save; + SaveSystem.SaveGame(); + }); + } + else + { + Infobox.Show("Uh oh.", "We couldn't find a save file with those values. Please try again", () => + { + LinkSaveFile(token); + }); + } + }; + ServerManager.MessageReceived += nsmr; + ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new { - Utils.Delete(Paths.GetPath("user.dat")); - } - string json = Utils.ExportMount(0); - System.IO.File.WriteAllText(Paths.SaveFile, json); - System.Diagnostics.Process.Start(Application.ExecutablePath); - Environment.Exit(0); - } + username = cuname, + password = cpass + })); + }, true); }); - + } + + public void ForceReboot() + { + string json = Utils.ExportMount(0); + System.IO.File.WriteAllText(Paths.SaveFile, json); + System.Diagnostics.Process.Start(Application.ExecutablePath); + Environment.Exit(0); } public void StartTrailer() diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index cf104fe..97ba8ef 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -367,6 +367,12 @@ <Compile Include="Tools\DitheringEngine.cs" /> <Compile Include="Tools\ShiftOSMenuRenderer.cs" /> <Compile Include="TrailerCommands.cs" /> + <Compile Include="UniteLoginDialog.cs"> + <SubType>UserControl</SubType> + </Compile> + <Compile Include="UniteLoginDialog.Designer.cs"> + <DependentUpon>UniteLoginDialog.cs</DependentUpon> + </Compile> <Compile Include="VisualBasicStuff.cs" /> <Compile Include="WFLanguageProvider.cs" /> <Compile Include="WidgetManager.cs" /> @@ -525,6 +531,9 @@ <EmbeddedResource Include="ShiftnetSites\MainHomepage.resx"> <DependentUpon>MainHomepage.cs</DependentUpon> </EmbeddedResource> + <EmbeddedResource Include="UniteLoginDialog.resx"> + <DependentUpon>UniteLoginDialog.cs</DependentUpon> + </EmbeddedResource> <EmbeddedResource Include="WindowBorder.resx"> <DependentUpon>WindowBorder.cs</DependentUpon> </EmbeddedResource> diff --git a/ShiftOS.WinForms/UniteLoginDialog.Designer.cs b/ShiftOS.WinForms/UniteLoginDialog.Designer.cs new file mode 100644 index 0000000..daf385b --- /dev/null +++ b/ShiftOS.WinForms/UniteLoginDialog.Designer.cs @@ -0,0 +1,123 @@ +namespace ShiftOS.WinForms +{ + partial class UniteLoginDialog + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.txtusername = new System.Windows.Forms.TextBox(); + this.txtpassword = new System.Windows.Forms.TextBox(); + this.btnlogin = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(16, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(84, 13); + this.label1.TabIndex = 0; + this.label1.Tag = "header2"; + this.label1.Text = "Login to ShiftOS"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(16, 82); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(58, 13); + this.label2.TabIndex = 1; + this.label2.Text = "Username:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(16, 115); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(56, 13); + this.label3.TabIndex = 2; + this.label3.Text = "Password:"; + // + // txtusername + // + this.txtusername.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtusername.Location = new System.Drawing.Point(112, 79); + this.txtusername.Name = "txtusername"; + this.txtusername.Size = new System.Drawing.Size(424, 20); + this.txtusername.TabIndex = 3; + // + // txtpassword + // + this.txtpassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtpassword.Location = new System.Drawing.Point(112, 112); + this.txtpassword.Name = "txtpassword"; + this.txtpassword.Size = new System.Drawing.Size(424, 20); + this.txtpassword.TabIndex = 4; + this.txtpassword.UseSystemPasswordChar = true; + // + // 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(460, 148); + this.btnlogin.Name = "btnlogin"; + this.btnlogin.Size = new System.Drawing.Size(75, 23); + this.btnlogin.TabIndex = 5; + this.btnlogin.Text = "Login"; + this.btnlogin.UseVisualStyleBackColor = true; + this.btnlogin.Click += new System.EventHandler(this.btnlogin_Click); + // + // UniteLoginDialog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.btnlogin); + this.Controls.Add(this.txtpassword); + this.Controls.Add(this.txtusername); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "UniteLoginDialog"; + this.Size = new System.Drawing.Size(573, 192); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtusername; + private System.Windows.Forms.TextBox txtpassword; + private System.Windows.Forms.Button btnlogin; + } +} diff --git a/ShiftOS.WinForms/UniteLoginDialog.cs b/ShiftOS.WinForms/UniteLoginDialog.cs new file mode 100644 index 0000000..4c85005 --- /dev/null +++ b/ShiftOS.WinForms/UniteLoginDialog.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using System.Net; + +namespace ShiftOS.WinForms +{ + public partial class UniteLoginDialog : UserControl, IShiftOSWindow + { + public UniteLoginDialog(Action<string> callback) + { + InitializeComponent(); + Callback = callback; + } + + private Action<string> Callback { get; set; } + + public void OnLoad() + { + this.ParentForm.AcceptButton = btnlogin; + } + + public void OnSkinLoad() + { + } + + public bool OnUnload() + { + return true; + } + + 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; + } + + try + { + var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Login?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4"); + 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(); + 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 + + } + } +} diff --git a/ShiftOS.WinForms/UniteLoginDialog.resx b/ShiftOS.WinForms/UniteLoginDialog.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/UniteLoginDialog.resx @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root>
\ No newline at end of file |
