diff options
| author | Michael <[email protected]> | 2017-04-30 17:50:50 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-30 17:50:54 -0400 |
| commit | cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae (patch) | |
| tree | 273464351e4bd65e60c083d4d35880fd43148dd3 /ShiftOS.WinForms/UniteLoginDialog.cs | |
| parent | 9a911c660feb1ef1177cc2bad002eb87004b6362 (diff) | |
| download | shiftos_thereturn-cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae.tar.gz shiftos_thereturn-cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae.tar.bz2 shiftos_thereturn-cdfba45faaa9202c69bdfe1a2f9e92140e0ecdae.zip | |
unite stuffs
Diffstat (limited to 'ShiftOS.WinForms/UniteLoginDialog.cs')
| -rw-r--r-- | ShiftOS.WinForms/UniteLoginDialog.cs | 90 |
1 files changed, 90 insertions, 0 deletions
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 + + } + } +} |
