public IActionResult SendContact() { try { string Subject = HttpContext.Request.Form["Subject"]; string Message = HttpContext.Request.Form["Message"]; string Name = HttpContext.Request.Form["Name"]; string Email = HttpContext.Request.Form["Email"]; string[] ValidationInputs = { Message, Name, Email }; if (!functions.ValidateInputs(ValidationInputs)) { TempData["ErrorMessage"] = "Validation error. Missing required field(s)."; return(RedirectToAction("Index", "Contact")); } //send email string ToName = _systemConfiguration.emailCompany; string[] MessageParagraphs = { "Contact message from " + Name + "<br/>", Message }; string PreHeader = "New contact message"; bool Button = false; int ButtonPosition = 0; string ButtonLink = null; string ButtonLinkText = null; string Closure = _systemConfiguration.emailClosure; string Company = _systemConfiguration.emailCompany; string UnsubscribeLink = null; string MessageBody = EmailFormating.FormatEmail(MessageParagraphs, PreHeader, Button, ButtonPosition, ButtonLink, ButtonLinkText, Closure, Company, UnsubscribeLink); string FromEmail = _systemConfiguration.smtpEmail; string ToEmail = functions.GetSiteLookupData("SupportEmail"); if (string.IsNullOrEmpty(Subject)) { Subject = "New Contact Message"; } EmailService.SendEmail(FromEmail, ToEmail, Subject, MessageBody, _systemConfiguration.smtpEmail, _systemConfiguration.smtpPass, _systemConfiguration.emailDisplayName, _systemConfiguration.smtpHost, _systemConfiguration.smtpPort); TempData["SuccessMessage"] = $"Thank you for getting in touch! We appreciate you contacting {_systemConfiguration.emailCompany}. <br/> One of our colleagues will get back in touch with you soon! <br/><br/> Have a great day!"; return(RedirectToAction("Index", "Contact")); } catch (Exception ex) { //Log Error _logger.LogInformation("Send Contact Message Error: " + ex.ToString()); TempData["ErrorMessage"] = "There was an error processing your request. Please try again. If this error persists, please send an email to the administrator."; return(RedirectToAction("Index", "Contact")); } }
//POST: PasswordReset/ResetPassword public IActionResult ResetPassword() { //get input values string ResetID = HttpContext.Request.Form["ResetID"]; string NewPassword = HttpContext.Request.Form["Password"]; string ConfirmPassword = HttpContext.Request.Form["ConfirmPassword"]; try { string[] ValidationInputs = { ResetID, NewPassword, ConfirmPassword }; if (!functions.ValidateInputs(ValidationInputs)) { TempData["ErrorMessage"] = "Validation error. Missing required field(s)."; return(RedirectToAction("Index", new { id = ResetID })); } //verify password match if (!functions.PasswordsMatch(NewPassword, ConfirmPassword)) { TempData["ErrorMessage"] = "Passwords do not match"; return(RedirectToAction("Index", new { id = ResetID })); } string AccountID = _context.PasswordForgot.Where(s => s.ResetID == ResetID).FirstOrDefault().AccountID; // get password var query = _context.Accounts.Where(s => s.AccountID == AccountID); string hashedPassword = (query.Any()) ? query.FirstOrDefault().Password : ""; //Update values NewPassword = BCrypt.Net.BCrypt.HashPassword(NewPassword); functions.UpdateTableData("Accounts", "AccountID", AccountID, "Password", NewPassword, _systemConfiguration.connectionString); TempData["SuccessMessage"] = "Account password has been reset successfully."; return(RedirectToAction("Index", "SignIn")); } catch (Exception ex) { //Log Error _logger.LogInformation("Reset Account Password Error: " + ex.ToString()); TempData["ErrorMessage"] = "There was an error processing your request. Please try again. If this error persists, please send an email to the administrator."; return(RedirectToAction("Index", new { id = ResetID })); } }
public IActionResult ResetPossword() { string ForgotEmail = HttpContext.Request.Form["ForgotPasswordEmail"]; string[] ValidationInputs = { ForgotEmail }; if (!functions.ValidateInputs(ValidationInputs)) { TempData["ErrorMessage"] = "Validation error. Email required."; return(RedirectToAction("Index", "SignIn")); } if (!_context.Accounts.Any(s => s.Email == ForgotEmail)) { TempData["ErrorMessage"] = "The email provided does not exist in our records."; return(RedirectToAction("Index", "SignIn")); } string AccountID = _context.Accounts.Where(s => s.Email == ForgotEmail).FirstOrDefault().AccountID; try { //remove other user reset data if exists functions.DeleteTableData("PasswordForgot", "AccountID", AccountID, _systemConfiguration.connectionString); //add reset data string ResetID = functions.RandomString(120); functions.AddForgotPassword(ResetID, AccountID); //send user email //set email data string ToName = functions.GetAccountData(AccountID, "FullName"); string[] MessageParagraphs = { "Hello, ", "We've received a request to reset the password for your account. No changes have been made to your account yet. You can reset your password by clicking the link below: ", "If you did not request a new password, please let us know immediately by replying to this email." }; string PreHeader = "Account password reset link notification."; bool Button = true; int ButtonPosition = 2; string ButtonLink = functions.GetSiteLookupData("AppDomain") + "/PasswordReset/?id=" + ResetID; string ButtonLinkText = "Reset Password"; string Closure = _systemConfiguration.emailClosure; string Company = _systemConfiguration.emailCompany; string UnsubscribeLink = _systemConfiguration.emailUnsubscribeLink; string MessageBody = EmailFormating.FormatEmail(MessageParagraphs, PreHeader, Button, ButtonPosition, ButtonLink, ButtonLinkText, Closure, Company, UnsubscribeLink); string FromEmail = _systemConfiguration.smtpEmail; string ToEmail = ForgotEmail; string Subject = "Password Reset Email"; //Get smtp details string smtpEmail = _systemConfiguration.smtpEmail; string smtpPass = _systemConfiguration.smtpPass; string displayName = _systemConfiguration.emailDisplayName; string smtpHost = _systemConfiguration.smtpHost; int smtpPort = _systemConfiguration.smtpPort; EmailService.SendEmail(FromEmail, ToEmail, Subject, MessageBody, smtpEmail, smtpPass, displayName, smtpHost, smtpPort); TempData["SuccessMessage"] = @"The email with further instructions was sent to the submitted email address. If you don’t receive a message in 5 minutes, " + "check the junk folder. If you are still experiencing any problems, contact support at " + functions.GetSiteLookupData("SupportEmail"); //log activity if (_systemConfiguration.logActivity) { string LogAction = $@"User '{ToName}' did password reset."; functions.LogActivity(ToEmail, ToEmail, "PasswordReset", LogAction); } return(RedirectToAction("Index", "SignIn")); } catch (Exception ex) { //Log Error _logger.LogInformation("Password Reset Error: " + ex.ToString()); TempData["ErrorMessage"] = "There was an error processing your request. Please try again. If this error persists, please send an email to the administrator."; return(RedirectToAction("Index", "SignIn")); } }