private void cmdLogin_Click(object sender, System.EventArgs e) { try { nHydrate.Generator.Common.nhydrateservice.MainService service = null; service = new nHydrate.Generator.Common.nhydrateservice.MainService(); service.Url = VersionHelper.SERVICE_URL; if (service.AuthenticateUser2(txtLoginEMail.Text, txtLoginPassword.Text, SecurityHelper.GetMachineID())) { AddinAppData.Instance.PremiumValidated = false; if (!string.IsNullOrEmpty(txtPremium.Text)) { var result = service.VerifyPremiumKey(txtLoginEMail.Text, txtLoginPassword.Text, SecurityHelper.GetMachineID(), txtPremium.Text); if (string.IsNullOrEmpty(result)) { AddinAppData.Instance.PremiumValidated = true; MessageBox.Show("The premium key has been verified and applied. All application features have been enabled.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { //Display the reason for the error MessageBox.Show("An error has occurred while verifing your premium key. The failure reason is listed below.\n\n'" + result + "'", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } MessageBox.Show("The login has been validated. Your machine has been verified.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); service.ResetStatistics(txtLoginEMail.Text, chkStat.Checked); var key = service.GetKey(txtLoginEMail.Text); AddinAppData.Instance.Key = key; AddinAppData.Instance.PremiumKey = txtPremium.Text; AddinAppData.Instance.AllowStats = chkStat.Checked; AddinAppData.Instance.Save(); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("The login could not be validated.", "Invalid Login!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("There was an error trying to register. Please visit the main nHydrate site to register: http://www.nHydrate.org.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void cmdOK_Click(object sender, System.EventArgs e) { txtFirstName.Text = txtFirstName.Text.Trim(); txtLastName.Text = txtLastName.Text.Trim(); txtEmail.Text = txtEmail.Text.Trim(); txtPassword.Text = txtPassword.Text.Trim(); if (txtFirstName.Text == string.Empty) { MessageBox.Show("The first name is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (txtLastName.Text == string.Empty) { MessageBox.Show("The last name is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (cboCountry.SelectedIndex == 0) { MessageBox.Show("The country is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (txtEmail.Text == string.Empty) { MessageBox.Show("The email is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (txtPassword.Text == string.Empty) { MessageBox.Show("The password is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (txtPassword.Text != txtVerify.Text) { MessageBox.Show("The password must be verified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var message = string.Empty; nHydrate.Generator.Common.nhydrateservice.MainService service = null; try { service = new nHydrate.Generator.Common.nhydrateservice.MainService(); service.Url = VersionHelper.SERVICE_URL; var document = new XmlDocument(); document.LoadXml("<a></a>"); XmlHelper.AddElement(document.DocumentElement, "firstname", txtFirstName.Text); XmlHelper.AddElement(document.DocumentElement, "lastname", txtLastName.Text); XmlHelper.AddElement(document.DocumentElement, "city", txtCity.Text); XmlHelper.AddElement(document.DocumentElement, "region", txtRegion.Text); XmlHelper.AddElement(document.DocumentElement, "postcode", txtPostalCode.Text); XmlHelper.AddElement(document.DocumentElement, "country", cboCountry.SelectedItem.ToString()); XmlHelper.AddElement(document.DocumentElement, "email", txtEmail.Text); XmlHelper.AddElement(document.DocumentElement, "premiumkey", txtPremium.Text); XmlHelper.AddElement(document.DocumentElement, "password", txtPassword.Text); XmlHelper.AddElement(document.DocumentElement, "machinekey", SecurityHelper.GetMachineID()); XmlHelper.AddElement(document.DocumentElement, "version", VersionHelper.GetCurrentVersion()); XmlHelper.AddElement(document.DocumentElement, "allowstats", chkStat.Checked.ToString().ToLower()); message = service.RegisterUser2(document.OuterXml); } catch (Exception ex) { MessageBox.Show("There was an error trying to register. Please visit the main nHydrate site to register: https://github.com/nHydrate/nHydrate.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!string.IsNullOrEmpty(message)) { MessageBox.Show(message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var key = string.Empty; try { key = service.GetKey(txtEmail.Text); } catch (Exception ex) { MessageBox.Show("There was an error trying to retrieve the key. Please visit the main nHydrate site to register: https://github.com/nHydrate/nHydrate.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Validate premium key AddinAppData.Instance.PremiumValidated = false; if (!string.IsNullOrEmpty(txtPremium.Text)) { var result = service.VerifyPremiumKey(txtEmail.Text, txtPassword.Text, SecurityHelper.GetMachineID(), txtPremium.Text); if (string.IsNullOrEmpty(result)) { AddinAppData.Instance.PremiumValidated = true; MessageBox.Show("The premium key has been verified and applied. All application features have been enabled.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { //Display the reason for the error MessageBox.Show("An error has occurred while verifing your premium key. The failure reason is listed below.\n\n'" + result + "'", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } AddinAppData.Instance.Key = key; AddinAppData.Instance.PremiumKey = txtPremium.Text; AddinAppData.Instance.AllowStats = chkStat.Checked; AddinAppData.Instance.Save(); this.DialogResult = DialogResult.OK; this.Close(); }