diff --git a/modules/profilereview/src/Auth/Process/ProfileReview.php b/modules/profilereview/src/Auth/Process/ProfileReview.php index 5a4cb9b..8aad1d9 100644 --- a/modules/profilereview/src/Auth/Process/ProfileReview.php +++ b/modules/profilereview/src/Auth/Process/ProfileReview.php @@ -222,7 +222,7 @@ public function process(array &$state): void $isHeadedToProfileUrl = self::isHeadedToProfileUrl($state, $this->profileUrl); $mfa = $this->getAttributeAllValues('mfa', $state); - $method = $this->getAttributeAllValues('method', $state); + $method = $this->getMethod($state); $profileReview = $this->getAttribute('profile_review', $state); if (!$isHeadedToProfileUrl) { @@ -240,7 +240,7 @@ public function process(array &$state): void } if (self::needToShow($profileReview, self::REVIEW_PAGE)) { - $this->redirectToProfileReview($state, $employeeId, $mfa['options'], $method['options']); + $this->redirectToProfileReview($state, $employeeId); } } @@ -264,48 +264,37 @@ public function process(array &$state): void * * @param array $state The state data. * @param string $employeeId The Employee ID of the user account. - * @param array $mfaOptions A list of the mfa options. - * @param array $methodOptions A list of the method options. */ - protected function redirectToProfileReview(&$state, $employeeId, $mfaOptions, $methodOptions) + protected function redirectToProfileReview(array &$state, string $employeeId): void { - assert('is_array($state)'); - - foreach ($mfaOptions as $key => $mfaOption) { - if ($mfaOption['type'] === 'manager') { - unset ($mfaOptions[$key]); - } - } + $mfaOptions = $this->getAllMfaOptionsExceptManager($state); + $methodOptions = $this->getMethod($state)['options']; if (count($mfaOptions) == 0 && count($methodOptions) == 0) { return; } - /* Save state and redirect. */ - $state['employeeId'] = $employeeId; - $state['profileUrl'] = $this->profileUrl; - $state['mfaOptions'] = $mfaOptions; - $state['methodOptions'] = $methodOptions; - $state['template'] = 'review'; - - $stateId = State::saveState($state, self::STAGE_SENT_TO_NAG); - $url = Module::getModuleURL('profilereview/nag.php'); - - $httpUtils = new HTTP(); - $httpUtils->redirectTrustedURL($url, array('StateId' => $stateId)); + $this->redirectToNag($state, $employeeId, 'review'); } /** + * Redirect user to a template + * * @param array $state * @param string $employeeId * @param string $template */ - protected function redirectToNag(&$state, $employeeId, $template) + protected function redirectToNag(array &$state, string $employeeId, string $template): void { + $mfaOptions = $this->getAllMfaOptionsExceptManager($state); + $methodOptions = $this->getMethod($state)['options']; + /* Save state and redirect. */ $state['employeeId'] = $employeeId; $state['mfaLearnMoreUrl'] = $this->mfaLearnMoreUrl; $state['profileUrl'] = $this->profileUrl; + $state['mfaOptions'] = $mfaOptions; + $state['methodOptions'] = $methodOptions; $state['template'] = $template; $stateId = State::saveState($state, self::STAGE_SENT_TO_NAG); @@ -315,6 +304,22 @@ protected function redirectToNag(&$state, $employeeId, $template) $httpUtils->redirectTrustedURL($url, array('StateId' => $stateId)); } + public function getMethod(array $state): ?array + { + return $this->getAttributeAllValues('method', $state); + } + + protected function getAllMfaOptionsExceptManager(array $state): array + { + $mfaOptions = $this->getAttributeAllValues('mfa', $state)['options']; + foreach ($mfaOptions as $key => $mfaOption) { + if ($mfaOption['type'] === 'manager') { + unset ($mfaOptions[$key]); + } + } + return $mfaOptions; + } + public static function hasSeenSplashPageRecently(string $page) { $session = Session::getSessionFromRequest();