public async Task <IActionResult> LoginAsync(UserViewModel user) { var usr = CustomersAuthenticationManager.Authenticate(user.Username, user.Password); if (usr == null) { TempData["PasswordError"] = "<tr style='color:red'><td colspan='2'>Password incorrect. Please try again.</td></tr>"; return(View()); } var claims = new List <Claim>() { new Claim(ClaimTypes.Name, usr.Username), new Claim("CustomerId", usr.CustomerId.ToString()), new Claim("FirstName", usr.CustFirstName) }; var claimsIdentity = new ClaimsIdentity(claims, "Cookies"); await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(claimsIdentity)); TempData["CustomerId"] = usr.CustomerId; TempData["CustomerFName"] = usr.CustFirstName; if (TempData["ReturnUrl"] == null) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(TempData["ReturnUrl"].ToString())); } }
/// <summary> /// Reroutes user to page depending on whether their answer to security question is correct. /// </summary> /// <param name="attempt"></param> /// <returns></returns> public ActionResult GetLink(string attempt) { if (attempt == null) { TempData["AnswerResponse"] = "<tr style='color:red'><td>Please enter an answer.</td></tr>"; return(RedirectToAction("SecurityQuestion", new { username = (string)TempData.Peek("Username") })); } else if (CustomersAuthenticationManager.SecurityQuestionAnsweredCorrect((string)TempData.Peek("Username"), attempt) == true) { return(RedirectToAction("LinkSent", "Account")); } else { TempData["AnswerResponse"] = "<tr style='color:red'><td>Incorrect answer; please try again.</td></tr>"; return(RedirectToAction("SecurityQuestion", new { username = (string)TempData.Peek("Username") })); } }
public ActionResult EditAuth1(int id, string user, string oldp, string newp, string confnewp) { var msg = "<p "; if (newp == confnewp) { if (CustomersAuthenticationManager.CheckOldPasswordThenUpdate(id, user, oldp, newp) == true) { msg += "style='color:blue;'> Password changed successfully!</p>"; } else { msg += "style='color:red;'> Current password was entered incorrectly| Password was not updated.</p>"; } } else { msg += "style='color:red;'>Confirm password does not match | Password was not updated.</p>"; } return(Content(msg)); }
/// <summary> /// View for people who forget password. Allows user to input answer to security question. /// </summary> /// <param name="username"></param> /// <returns></returns> public ActionResult SecurityQuestion(string username) { if (username == null) { TempData["UsernameError"] = "<tr style='color:red'><td>Please enter a username.</td></tr>"; return(RedirectToAction("ForgotPassword")); } else { string question = CustomersAuthenticationManager.GetSecurityQuestion(username); if (question == null) { TempData["UsernameError"] = "<tr style='color:red'><td>Invalid username.<br />Please check your spelling.</td></tr>"; return(RedirectToAction("ForgotPassword")); } else { TempData["Username"] = username; TempData["Security Question"] = question; return(View()); } } }
public ActionResult EditAuth(int id) { CustomersAuthentication cust = CustomersAuthenticationManager.GetByCustomerId(id); return(View(cust)); }
public ActionResult RegisterDetails(Customer c) { List <SelectListItem> securityQuestions = new List <SelectListItem>() { new SelectListItem { Text = "What is your mother's maiden name?", Value = "What is your mother's maiden name?" }, new SelectListItem { Text = "Where did you attend high school?", Value = "Where did you attend high school?" }, new SelectListItem { Text = "Why is Eric always dressed so nicely?", Value = "Why is Eric always dressed so nicely?" }, new SelectListItem { Text = "What is your favourite TV show?", Value = "What is your favourite TV show?" } }; ViewBag.SecurityQuestions = securityQuestions; List <SelectListItem> provinces = new List <SelectListItem>() { new SelectListItem { Text = "", Value = "" }, new SelectListItem { Text = "AB", Value = "AB" }, new SelectListItem { Text = "BC", Value = "BC" }, new SelectListItem { Text = "MB", Value = "MB" }, new SelectListItem { Text = "NB", Value = "NB" }, new SelectListItem { Text = "NL", Value = "NL" }, new SelectListItem { Text = "NS", Value = "NS" }, new SelectListItem { Text = "NT", Value = "NT" }, new SelectListItem { Text = "NU", Value = "NU" }, new SelectListItem { Text = "ON", Value = "ON" }, new SelectListItem { Text = "PE", Value = "PE" }, new SelectListItem { Text = "QC", Value = "QC" }, new SelectListItem { Text = "SK", Value = "SK" }, new SelectListItem { Text = "YK", Value = "YK" } }; ViewBag.Provinces = provinces; if (ModelState.IsValid) { if (CustomersAuthenticationManager.UsernameIsTaken(c.CustomersAuthentication.Username) == true) { ViewBag.Message = "User Name " + c.CustomersAuthentication.Username + " already exists"; return(View()); } else { try { CustomerManager.Add(c); TempData["LoginPrompt"] = "<script>alert('Your account has been created. You may log in with your username and password.');</script>"; return(RedirectToAction("Login", "Account")); } catch { return(View()); } } } else { return(View()); } }