void buttonPassword_Click(object sender, EventArgs e) { this.widgetEmailFeedback.Reset(); this.widgetPasswordFeedback.Reset(); FormChecker checker = new FormChecker(); string password = checker.GetStringValue(new ControlReference(this.textPassword, "Password"), true); string confirm = checker.GetStringValue(new ControlReference(this.textConfirm, "Confirm"), true); // check... if (!(checker.HasErrors)) { // match? if (password == confirm) { // set... this.CurrentUser.SetPassword(password, true); // show... this.widgetPasswordFeedback.SetInfo("Your password has been changed."); } else checker.AddError("The passwords do not match."); } // show... if (checker.HasErrors) this.widgetPasswordFeedback.SetError(checker); }
void buttonReset_Click(object sender, EventArgs e) { this.widgetFeedback.Reset(); // get... FormChecker checker = new FormChecker(); string email = checker.GetStringValue(new ControlReference(this.textEmail, "Email"), true); // not... if(!(checker.HasErrors)) { // find... ApiKey key = ApiKey.GetByEmail(email); if (key != null) { // reset... string password = key.ResetPassword(); // send... IDictionary values = CollectionsUtil.CreateCaseInsensitiveHashtable(); values["password"] = password; EmailHelper.SendEmail(EmailKeys.ForgotPassword, key, values); // show... this.widgetFeedback.SetInfo("Your new password has been sent."); } else checker.AddError(string.Format("An account for email address '{0}' was not found.", email)); } // show... if (checker.HasErrors) this.widgetFeedback.SetError(checker); }
void buttonLogon_Click(object sender, EventArgs e) { this.widgetFeedback.Reset(); // get... FormChecker checker = new FormChecker(this); string username = checker.GetStringValue(new ControlReference(this.textUsername, "Username"), true); string password = checker.GetStringValue(new ControlReference(this.textPassword, "Password"), true); // not... if (!(checker.HasErrors)) { // find... ApiKey key = ApiKey.GetByUsername(username); if (key != null) { if (key.IsActive) { // password... string hashed = EncryptionHelper.HashPasswordToBase64String(password, key.PasswordSalt); if (hashed == key.PasswordHash) { // logon... RememberUserFlags flags = RememberUserFlags.DoNotRememberUsers; if(this.checkRemember.Checked) flags = RememberUserFlags.UsernameAndPassword; this.Logon(key, flags, new TimeSpan(90, 0, 0, 0)); // go... this.Response.Redirect("~/default.aspx"); } else checker.AddError("The password is invalid."); } else checker.AddError("The API account is not active."); } else checker.AddError("The username is invalid."); } // show... if (checker.HasErrors) this.widgetFeedback.SetError(checker); }
void buttonEmail_Click(object sender, EventArgs e) { this.widgetEmailFeedback.Reset(); this.widgetPasswordFeedback.Reset(); FormChecker checker = new FormChecker(); string email = checker.GetStringValue(new ControlReference(this.textEmail, "Email"), true); // check... if (!(checker.HasErrors)) { // get... ApiKey existing = ApiKey.GetByEmail(email); if (existing == null) { // set... this.CurrentUser.Email = email; this.CurrentUser.SaveChanges(); // show... this.widgetEmailFeedback.SetInfo("The email address has been changed."); } else { // us? if(CurrentUser == null) throw new InvalidOperationException("'CurrentUser' is null."); if (existing.ApiKeyId == this.CurrentUser.ApiKeyId) checker.AddError("Please enter a new email address."); else checker.AddError("Another account is already using this email address."); } } // show... if (checker.HasErrors) this.widgetEmailFeedback.SetError(checker); }
void buttonSave_Click(object sender, EventArgs e) { this.widgetFeedback.Reset(); // get... FormChecker checker = new FormChecker(); string username = checker.GetStringValue(new ControlReference(this.textUsername, "Username"), true); string password = checker.GetStringValue(new ControlReference(this.textPassword, "Password"), true); string confirm = checker.GetStringValue(new ControlReference(this.textConfirm, "Confirm"), true); string firstName = checker.GetStringValue(new ControlReference(this.textFirstName, "First name"), true); string lastName = checker.GetStringValue(new ControlReference(this.textLastName, "Last name"), true); string company = checker.GetStringValue(new ControlReference(this.textCompany, "Company"), true); string address1 = checker.GetStringValue(new ControlReference(this.textAddress1, "Address 1"), true); string address2 = checker.GetStringValue(new ControlReference(this.textAddress2, "Address 2"), false); string address3 = checker.GetStringValue(new ControlReference(this.textAddress3, "Address 3"), false); string city = checker.GetStringValue(new ControlReference(this.textCity, "City/town"), true); string region = checker.GetStringValue(new ControlReference(this.textRegion, "Region/county"), false); string postalCode = checker.GetStringValue(new ControlReference(this.textPostalCode, "Postal code/postcode"), true); Country country = (Country)checker.GetEntity(new ControlReference(this.listCountry, "Country"), typeof(Country), true); string email = checker.GetStringValue(new ControlReference(this.textEmail, "Email"), true); // not... if (!(checker.HasErrors)) { // check... if (password == confirm) { // find... ApiKey existing = ApiKey.GetByUsername(username); if (existing == null) { // check email... ApiKey byUser = ApiKey.GetByEmail(email); if(byUser == null) { // create... ApiKey key = new ApiKey(); key.Username = username; key.SetPassword(password, false); key.FirstName = firstName; key.LastName = lastName; key.Company = company; key.Address1 = address1; key.Address2 = address2; key.Address3 = address3; key.City = city; key.Region = region; key.PostalCode = postalCode; key.Country = country; key.Email = email; key.Subscribe = this.checkSubscribe.Checked; key.IsActive = true; // save... key.SaveChanges(); // send... EmailHelper.SendEmail(EmailKeys.NewRegistration, key); // logon... this.Logon(key, RememberUserFlags.DoNotRememberUsers, TimeSpan.MinValue); // redirect... this.Response.Redirect("~/"); } else checker.AddError(string.Format("The email address '{0}' has already been used.", email)); } else checker.AddError(string.Format("The username '{0}' already exists.", username)); } else checker.AddError("Passwords do not match."); } // not... if (checker.HasErrors) this.widgetFeedback.SetError(checker); }