public ActionResult SecretQA(Logins logins) { bool valid = false; var uid = logins.UID; var username = logins.UserName; int errors = logins.Errors; TempData["UID"] = logins.UID; TempData["UserName"] = logins.UserName; TempData["Question"] = logins.SecretQuestion; TempData["Errors"] = logins.Errors; try { if (String.IsNullOrEmpty(logins.SecretQuestion) || String.IsNullOrEmpty(logins.SecretAnswer)) { TempData["Message"] = "Secret Question and Secret Answer need to be entered."; return RedirectToAction("SecretQA"); } else { // validate question and answer - username will always be present if (!String.IsNullOrEmpty(logins.SecretQuestion) && !String.IsNullOrEmpty(logins.SecretAnswer)) { if (username != null) { if (Linqs.CheckAnswer(username, logins.SecretQuestion, logins.SecretAnswer)) { string emailAdd = null; if (Linqs.GetEmailAddress(ref emailAdd, uid)) { if (Linqs.UpdateLoginRecord(processor, emailAdd, Convert.ToString(username), uid)) { valid = true; TempData["Message"] = "Your will receive a new password soon."; return RedirectToAction("SecretQA"); } } } else { errors += 1; if(errors == 3) { TempData["Errors"] = errors; Linqs.IncrementErrors(uid); // display account locked out message TempData["Message"] = "Your account has been locked. You can unlock your account by contacting the web administrator via email at [email protected] or [email protected]."; return RedirectToAction("SecretQA"); } else if(errors < 3) { TempData["Errors"] = errors; Linqs.IncrementErrors(uid); } } } } // display error if (!valid) { if(errors > 3) { TempData["Message"] = "Your account has been locked. You can unlock your account by contacting the web administrator via email at [email protected] or [email protected]."; } else { TempData["Message"] = "Incorrect entry. You have " + (3 - errors) + " tries left."; } return RedirectToAction("SecretQA"); } } } catch (Exception ex) { processor.ProcessSendErrorEmail(ex.Message + "\n\n" + ex.ToString(), "BP SecretQA"); ViewBag.Message = "Some error has occurred. Please try again later."; } return View(); }
public ActionResult SecretQA() { Logins login = new Logins(); login.UID = (int)TempData["UID"]; login.UserName = (string)TempData["UserName"]; login.SecretQuestion = (string)TempData["Question"]; login.Errors = (int)TempData["Errors"]; return View(login); }