// Handles submission of admin registration form protected void btnSubmit_Click(object sender, EventArgs e) { if (IsValid) { string password = BLPassword.RandomString(10, true); string mailbody = "<p>" + "Hi," + "</p>" + "<p>" + "Below is the verification link needed to update your password (click to update):" + "</p>" + "<p>" + "https://localhost:44326/UL/ChangePassword/" + tbxUsername.Text + "/" + password + "</p>" + "<br/>" + "<p>" + "Kind Regards," + "</p>" + "<p>" + "The JerseySure Team" + "</p>"; try { BLEmail.SendEmail(tbxUsername.Text, "Admin Verification Link - JerseySure", mailbody); } catch (Exception ex) { Response.Redirect("~/UL/ErrorPage/1"); } BLUser newUser = new BLUser { userFirstName = tbxFirstName.Text, userLastName = tbxLastName.Text, userEmail = tbxUsername.Text, userPhone = tbxPhone.Text, billAddress = null, postAddress = BLAddress.fillAddress('P', tbxAddress.Text, tbxSuburb.Text, ddlState.SelectedValue, Convert.ToInt32(tbxPostCode.Text)), userPassword = password, userAdmin = true, userActive = true }; // Add admin account BLUser.addUser(newUser); // View saying verification email has been sent Response.Redirect("~/UL/SuccessPage/0"); } }
protected void RequestButton_Click(object sender, EventArgs e) { if (IsValid) { // Check if email exists in the system; reload page and display error if not -- X // If exists, update password to random generated string; password is hashed for security string randomCode = BLPassword.RandomString(10, true); // Retrieve user corresponding to email address of account and update password BLUser user = new BLUser(); user = user.getUserByEmail(EmailTextBox.Text); BLUser.updateUserPassword(user, randomCode); // Attach email address and hashed password as parameters for url to update password (sent in the email) string mailbody = "<p>" + "Hi," + "</p>" + "<p>" + "Below is the verification link needed to update your password (click to update):" + "</p>" + "<p>" + "https://localhost:44326/UL/ChangePassword/" + EmailTextBox.Text + "/" + randomCode + "</p>" + "<br/>" + "<p>" + "Kind Regards," + "</p>" + "<p>" + "The JerseySure Team" + "</p>"; try { BLEmail.SendEmail(EmailTextBox.Text, "Verification Link - JerseySure", mailbody); } catch (Exception ex) { // Display error page for unable to send email Response.Redirect("~/UL/ErrorPage/1"); } // Display success status of email being sent Response.Redirect("~/UL/SuccessPage/0"); } }