public async Task <IActionResult> SetupChallengeQuestions() { string username = HttpContext.Session.GetString(AuthenticationChallengeConstants.SessionKeyUsername); if (username != null) { IQueryable <ChallengeQuestion> questions = _context.ChallengeQuestions.Take(2); SetupChallengeQuestionsViewModel model = new SetupChallengeQuestionsViewModel { Username = username, Question1 = questions.First(), Question2 = questions.Skip(1).First() }; return(await Task.FromResult(View(model))); } return(await Task.FromResult(RedirectToAction(nameof(Login), new { Message = AuthenticationChallengeConstants.LoginPageMessageFailure }))); }
public async Task <IActionResult> SetupChallengeQuestions(SetupChallengeQuestionsViewModel model) { if (ModelState.IsValid) { string username = HttpContext.Session.GetString(AuthenticationChallengeConstants.SessionKeyUsername); if (username != null) { model.Username = username; ApplicationUser user = _userManager.Users.SingleOrDefault(u => u.UserName == username); user.Question1 = _context.ChallengeQuestions.SingleOrDefault(q => q.ID == model.Question1.ID); user.Question2 = _context.ChallengeQuestions.SingleOrDefault(q => q.ID == model.Question2.ID); user.Answer1 = model.Answer1; user.Answer2 = model.Answer2; await _userManager.UpdateAsync(user); return(RedirectToAction(nameof(ManageController.Index), nameof(ManageController).Replace("Controller", ""))); } } return(RedirectToAction(nameof(Login), new { Message = AuthenticationChallengeConstants.LoginPageMessageFailure })); }
public async Task <IActionResult> AnswerChallengeQuestions(SetupChallengeQuestionsViewModel model) { if (ModelState.IsValid) { string username = HttpContext.Session.GetString(AuthenticationChallengeConstants.SessionKeyUsername); if (username != null) { model.Username = username; ApplicationUser user = _userManager.Users.SingleOrDefault(u => u.UserName == username); if (user.VerifyAnswers(model.Answer1, model.Answer2)) { HttpContext.Session.SetInt32(AuthenticationChallengeConstants.SessionKeyAnsweredChallengeQuestions, 1); return(await Task.FromResult(RedirectToAction(nameof(EnterPassword)))); } ModelState.AddModelError(string.Empty, "Authentication failed"); return(await Task.FromResult(View(model))); } } return(await Task.FromResult(RedirectToAction(nameof(Login), new { Message = AuthenticationChallengeConstants.LoginPageMessageFailure }))); }