diff options
Diffstat (limited to 'ShiftOS.WinForms/UniteSignupDialog.cs')
| -rw-r--r-- | ShiftOS.WinForms/UniteSignupDialog.cs | 97 |
1 files changed, 18 insertions, 79 deletions
diff --git a/ShiftOS.WinForms/UniteSignupDialog.cs b/ShiftOS.WinForms/UniteSignupDialog.cs index 7d0fd33..b2b5052 100644 --- a/ShiftOS.WinForms/UniteSignupDialog.cs +++ b/ShiftOS.WinForms/UniteSignupDialog.cs @@ -16,13 +16,19 @@ namespace ShiftOS.WinForms { public partial class UniteSignupDialog : UserControl, IShiftOSWindow { - public UniteSignupDialog(Action<string> callback) + public class SignupCredentials + { + public string SystemName { get; set; } + public string RootPassword { get; set; } + } + + public UniteSignupDialog(Action<SignupCredentials> callback) { InitializeComponent(); Callback = callback; } - private Action<string> Callback { get; set; } + private Action<SignupCredentials> Callback { get; set; } public void OnLoad() @@ -45,92 +51,25 @@ namespace ShiftOS.WinForms private void btnlogin_Click(object sender, EventArgs e) { - string u = txtusername.Text; - string p = txtpassword.Text; + string sys = txtsys.Text; + string root = txtroot.Text; - if (string.IsNullOrWhiteSpace(u)) + if (string.IsNullOrWhiteSpace(sys)) { - Infobox.Show("Please enter a username.", "You must enter a proper email address."); + Infobox.Show("{TITLE_EMPTY_SYSNAME}", "{MSG_EMPTY_SYSNAME}"); return; } - - if (string.IsNullOrWhiteSpace(p)) + if(sys.Length < 5) { - Infobox.Show("Please enter a password.", "You must enter a valid password."); + Infobox.Show("{TITLE_VALIDATION_ERROR}", "{MSG_VALIDATION_ERROR_SYSNAME_LENGTH}"); return; } - if(p != txtconfirm.Text) + Callback?.Invoke(new SignupCredentials { - 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(UserConfig.Get().UniteUrl + "/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 + SystemName = sys, + RootPassword = root + }); } } |
