public ActionResult ResetWithQuestions(PasswordResetWithSecretInputModel model)
{
if (ModelState.IsValid)
{
try
{
var answers =
model.Questions.Select(x => new PasswordResetQuestionAnswer { QuestionID = x.QuestionID, Answer = x.Answer });
this.userAccountService.ResetPasswordFromSecretQuestionAndAnswer(model.UnprotectedAccountID.Value, answers.ToArray());
return View("ResetSuccess");
}
catch (ValidationException ex)
{
ModelState.AddModelError("", ex.Message);
}
}
var id = model.UnprotectedAccountID;
if (id != null)
{
var account = this.userAccountService.GetByID(id.Value);
if (account != null)
{
var vm = new PasswordResetWithSecretInputModel(account.ID);
vm.Questions =
account.PasswordResetSecrets.Select(
x => new PasswordResetSecretViewModel
{
QuestionID = x.PasswordResetSecretID,
Question = x.Question
}).ToArray();
return View("ResetWithQuestions", vm);
}
}
return RedirectToAction("Index");
}