コード例 #1
0
        public ActionResult SelectQuestions(ViewModel.SecurityQuestionsViewModel usrQuestionInfo)
        {
            try
            {
                List <string> securityQuestionList = new List <string>();
                _logMessages.AppendFormat("Setting up user security questions for user {0}.", Identity.UserName);

                //getting list of security questions
                _logMessages.Append("Getting security question list.");
                securityQuestionList = _restClient.GetSecurityQuestionList();

                usrQuestionInfo.SecurityQuestions = securityQuestionList;
                if (ModelState.IsValid)
                {
                    List <string> selectedSecQuestions = new List <string>();
                    selectedSecQuestions.Add(usrQuestionInfo.PrimarySelectedQuestion.Trim().ToLower());
                    selectedSecQuestions.Add(usrQuestionInfo.SecondarySelectedQuestion.Trim().ToLower());
                    selectedSecQuestions.Add(usrQuestionInfo.ThirdSelectedQuestion.Trim().ToLower());

                    //do a distinct on the selected questions and check if there are 3 unique questions
                    if (selectedSecQuestions.Distinct().Count() != 3)
                    {
                        ModelState.AddModelError(string.Empty, "Please select unique security questions.");
                        return(View(usrQuestionInfo));
                    }

                    if (string.IsNullOrEmpty(usrQuestionInfo.PrimaryProvidedAnswer) ||
                        string.IsNullOrEmpty(usrQuestionInfo.SecondaryProvidedAnswer) ||
                        string.IsNullOrEmpty(usrQuestionInfo.ThirdProvidedAnswer))
                    {
                        ModelState.AddModelError(string.Empty, "Please provide answers to your security questions");
                        return(View(usrQuestionInfo));
                    }

                    List <AHP.Core.DTO.UserSecurityOption> selectedQuestions = new List <Core.DTO.UserSecurityOption>();
                    selectedQuestions.Add(new Core.DTO.UserSecurityOption()
                    {
                        Answer   = usrQuestionInfo.PrimaryProvidedAnswer,
                        Question = usrQuestionInfo.PrimarySelectedQuestion
                    });
                    selectedQuestions.Add(new Core.DTO.UserSecurityOption()
                    {
                        Answer   = usrQuestionInfo.SecondaryProvidedAnswer,
                        Question = usrQuestionInfo.SecondarySelectedQuestion
                    });
                    selectedQuestions.Add(new Core.DTO.UserSecurityOption()
                    {
                        Answer   = usrQuestionInfo.ThirdProvidedAnswer,
                        Question = usrQuestionInfo.ThirdSelectedQuestion
                    });

                    GenericAjaxResponse <bool> response = _restClient.SetSecurityQuestionsForUser(Identity.UserName, selectedQuestions);

                    if (response.Success && response.Data)
                    {
                        Dictionary <string, string> claimValues = new Dictionary <string, string>();
                        claimValues.Add(AHP.Core.ClaimTypes.MustChangeSecurityQuestion, bool.FalseString);
                        //Update the claim value
                        _authManager.UpdateClaim(Request, claimValues);

                        //redirect to customer home pae
                        return(RedirectToAction("Home", "Customer"));
                    }
                    ModelState.AddModelError(string.Empty, response.Errors[0]);
                    return(View(usrQuestionInfo));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, "An error occurred. Please try again.");
                _logMessages.AppendFormat("Exception occurred updating security questions. Exception info {0}.", ex.Message);
            }
            _logger.Info(_logMessages.ToString());
            //show the view if it has come till here
            return(View(usrQuestionInfo));
        }