@@ -144,31 +144,7 @@ public async Task<IActionResult> Index(string returnUrl)
144144
145145 if ( currentStage ? . Id == ( int ) LoginWizardStageEnum . SecurityQuestions )
146146 {
147- SecurityQuestionsViewModel securityQuestions = await this . loginWizardService . GetSecurityQuestionsModel ( this . CurrentUserId ) ;
148-
149- while ( securityQuestions . UserSecurityQuestions . Count < this . Settings . SecurityQuestionsToAsk )
150- {
151- securityQuestions . UserSecurityQuestions . Add ( new UserSecurityQuestionViewModel ( ) ) ;
152- }
153-
154- foreach ( var answer in securityQuestions . UserSecurityQuestions )
155- {
156- if ( ! string . IsNullOrEmpty ( answer . SecurityQuestionAnswerHash ) )
157- {
158- answer . SecurityQuestionAnswerHash = "********" ;
159- }
160- }
161-
162- this . TempData . Clear ( ) ;
163- var securityViewModel = new SecurityViewModel ( )
164- {
165- SecurityQuestions = securityQuestions . SecurityQuestions ,
166- UserSecurityQuestions = securityQuestions . UserSecurityQuestions ,
167- } ;
168-
169- await this . multiPageFormService . SetMultiPageFormData ( securityViewModel , MultiPageFormDataFeature . EditRegistrationPrompt , this . TempData ) ;
170-
171- return this . RedirectToAction ( "SelectSecurityQuestion" , new RouteValueDictionary { { "questionIndex" , 0 } , { "returnUrl" , returnUrl } } ) ;
147+ return this . RedirectToAction ( "SelectSecurityQuestions" , new { returnUrl } ) ;
172148 }
173149
174150 if ( currentStage ? . Id == ( int ) LoginWizardStageEnum . JobRole || currentStage ? . Id == ( int ) LoginWizardStageEnum . PlaceOfWork || currentStage ? . Id == ( int ) LoginWizardStageEnum . PersonalDetails )
@@ -213,11 +189,19 @@ await this.multiPageFormService.SetMultiPageFormData(
213189 {
214190 return this . RedirectToAction ( "AccountInformationNeeded" ) ;
215191 }
192+ else if ( currentStage ? . Id == ( int ) LoginWizardStageEnum . JobRole || currentStage ? . Id == ( int ) LoginWizardStageEnum . PlaceOfWork )
193+ {
194+ return this . RedirectToAction ( "MyEmploymentDetails" , "MyAccount" , new { returnUrl , checkDetails = true } ) ;
195+ }
216196 else
217197 {
218198 return this . RedirectToAction ( "Index" , "MyAccount" , new { returnUrl , checkDetails = true } ) ;
219199 }
220200 }
201+ else if ( currentStage ? . Id == ( int ) LoginWizardStageEnum . JobRole || currentStage ? . Id == ( int ) LoginWizardStageEnum . PlaceOfWork )
202+ {
203+ return this . RedirectToAction ( "MyEmploymentDetails" , "MyAccount" , new { returnUrl , checkDetails = true } ) ;
204+ }
221205 else
222206 {
223207 return this . RedirectToAction ( "Index" , "MyAccount" , new { returnUrl , checkDetails = true } ) ;
@@ -585,6 +569,106 @@ public async Task<ActionResult> AccountConfirmationPost()
585569 return this . RedirectToAction ( "Index" , new RouteValueDictionary { { "returnUrl" , accountModel . WizardReturnUrl } } ) ;
586570 }
587571
572+ /// <summary>
573+ /// Action for starting the security question multiPageForm stage of the wizard.
574+ /// </summary>
575+ /// <param name="returnUrl">The URL to return to after the login wizard has been completed.</param>
576+ /// <returns>The <see cref="Task{IActionResult}"/>.</returns>
577+ [ ResponseCache ( CacheProfileName = "Never" ) ]
578+ public async Task < IActionResult > SelectSecurityQuestions ( string returnUrl )
579+ {
580+ MyAcountSecurityQuestionsViewModel securityViewModel = new MyAcountSecurityQuestionsViewModel ( ) ;
581+ var result = await this . loginWizardService . GetSecurityQuestionsModel ( this . CurrentUserId ) ;
582+
583+ if ( result != null )
584+ {
585+ securityViewModel . FirstSecurityQuestions = SelectListHelper . MapSelectListWithSelection ( result . SecurityQuestions , Convert . ToString ( securityViewModel . SelectedFirstQuestionId ) ) ;
586+ securityViewModel . SecondSecurityQuestions = SelectListHelper . MapSelectListWithSelection ( result . SecurityQuestions , Convert . ToString ( securityViewModel . SelectedSecondQuestionId ) ) ;
587+ }
588+
589+ this . ViewBag . ReturnUrl = returnUrl ;
590+ return this . View ( "SecurityQuestionsDetails" , securityViewModel ) ;
591+ }
592+
593+ /// <summary>
594+ /// Action for choosing security questions.
595+ /// </summary>
596+ /// <param name="model">The MyAcountSecurityQuestionsViewModel.</param>
597+ /// <param name="returnUrl">The URL to return to after the login wizard has been completed.</param>
598+ /// <returns>The <see cref="Task{IActionResult}"/>.</returns>
599+ [ HttpPost ]
600+ [ ResponseCache ( CacheProfileName = "Never" ) ]
601+ public async Task < IActionResult > UpdateSecurityQuestionPost ( MyAcountSecurityQuestionsViewModel model , string returnUrl )
602+ {
603+ MyAcountSecurityQuestionsViewModel securityViewModel = new MyAcountSecurityQuestionsViewModel ( ) ;
604+ var result = await this . loginWizardService . GetSecurityQuestionsModel ( this . CurrentUserId ) ;
605+
606+ if ( result != null )
607+ {
608+ securityViewModel . FirstSecurityQuestions = SelectListHelper . MapSelectListWithSelection ( result . SecurityQuestions , Convert . ToString ( securityViewModel . SelectedFirstQuestionId ) ) ;
609+ securityViewModel . SecondSecurityQuestions = SelectListHelper . MapSelectListWithSelection ( result . SecurityQuestions , Convert . ToString ( securityViewModel . SelectedSecondQuestionId ) ) ;
610+ }
611+
612+ if ( model != null )
613+ {
614+ if ( model . SelectedFirstQuestionId == model . SelectedSecondQuestionId )
615+ {
616+ this . ModelState . AddModelError ( "DuplicateQuestion" , CommonValidationErrorMessages . DuplicateQuestion ) ;
617+ }
618+
619+ if ( model . SelectedFirstQuestionId > 0 && string . IsNullOrEmpty ( model . SecurityFirstQuestionAnswerHash ) )
620+ {
621+ this . ModelState . AddModelError ( nameof ( model . SecurityFirstQuestionAnswerHash ) , CommonValidationErrorMessages . InvalidSecurityQuestionAnswer ) ;
622+ }
623+
624+ if ( model . SelectedSecondQuestionId > 0 && string . IsNullOrEmpty ( model . SecuritySecondQuestionAnswerHash ) )
625+ {
626+ this . ModelState . AddModelError ( nameof ( model . SecuritySecondQuestionAnswerHash ) , CommonValidationErrorMessages . InvalidSecurityQuestionAnswer ) ;
627+ }
628+
629+ if ( this . ModelState . IsValid )
630+ {
631+ var userSecurityQuestions = new List < UserSecurityQuestionViewModel >
632+ {
633+ new UserSecurityQuestionViewModel
634+ {
635+ SecurityQuestionId = model . SelectedFirstQuestionId ,
636+ SecurityQuestionAnswerHash = model . SecurityFirstQuestionAnswerHash ,
637+ UserId = this . CurrentUserId ,
638+ } ,
639+ new UserSecurityQuestionViewModel
640+ {
641+ SecurityQuestionId = model . SelectedSecondQuestionId ,
642+ SecurityQuestionAnswerHash = model . SecuritySecondQuestionAnswerHash ,
643+ UserId = this . CurrentUserId ,
644+ } ,
645+ } ;
646+
647+ await this . userService . UpdateUserSecurityQuestions ( userSecurityQuestions ) ;
648+
649+ // Mark stage complete.
650+ var ( cacheExists , loginWizard ) = await this . cacheService . TryGetAsync < LoginWizardViewModel > ( this . LoginWizardCacheKey ) ;
651+
652+ if ( cacheExists )
653+ {
654+ await this . CompleteLoginWizardStageAsync ( loginWizard , LoginWizardStageEnum . SecurityQuestions ) ;
655+ this . TempData . Clear ( ) ;
656+ return this . RedirectToAction ( "Index" , new RouteValueDictionary { { "returnUrl" , returnUrl } } ) ;
657+ }
658+
659+ this . TempData . Clear ( ) ;
660+ return this . Redirect ( "/" ) ;
661+ }
662+ else
663+ {
664+ this . ViewBag . ReturnUrl = returnUrl ;
665+ return this . View ( "SecurityQuestionsDetails" , securityViewModel ) ;
666+ }
667+ }
668+
669+ return this . View ( "SecurityQuestionsDetails" , securityViewModel ) ;
670+ }
671+
588672 /// <summary>
589673 /// The complete login wizard stage.
590674 /// </summary>
0 commit comments