From dc17977d6fa92e2c1122e817f5f10e6715b16d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Vysko=C4=8Dil?= Date: Thu, 2 Jan 2020 15:01:48 +0100 Subject: [PATCH] Added new proccess filter to redirect some users to selected page. --- dictionaries/perun.definition.json | 12 +++ lib/Auth/Process/RedirectSomeUsers.php | 104 +++++++++++++++++++++++++ templates/redirect_some_users-tpl.php | 54 +++++++++++++ www/redirect_some_users.php | 28 +++++++ www/redirect_some_users_continue.php | 9 +++ 5 files changed, 207 insertions(+) create mode 100644 lib/Auth/Process/RedirectSomeUsers.php create mode 100644 templates/redirect_some_users-tpl.php create mode 100644 www/redirect_some_users.php create mode 100644 www/redirect_some_users_continue.php diff --git a/dictionaries/perun.definition.json b/dictionaries/perun.definition.json index 8f77a612..c24e280c 100644 --- a/dictionaries/perun.definition.json +++ b/dictionaries/perun.definition.json @@ -94,5 +94,17 @@ "unauthorized-access_redirect_to_registration": { "en": "Now you will be redirected to registration to Perun system.", "cs": "Nyní budete přesměrování na registraci do systému Perun." + }, + "redirect_some_users-header": { + "en": "Your activity is necessary to access the service", + "cs": "Pro přístup ke službě je vyžadována vaše aktivita" + }, + "redirect_some_users-text": { + "en": "Text", + "cs": "Text" + }, + "continue_to_service": { + "en": "You can continue to the service", + "cs": "Na službu můžete pokračovat" } } diff --git a/lib/Auth/Process/RedirectSomeUsers.php b/lib/Auth/Process/RedirectSomeUsers.php new file mode 100644 index 00000000..12a787cc --- /dev/null +++ b/lib/Auth/Process/RedirectSomeUsers.php @@ -0,0 +1,104 @@ +attributeIdentifier = (string)$config[self::ATTRIBUTE_IDENTIFIER]; + $this->URLWtithLogins = (string)$config[self::URL_WITH_LOGINS]; + if (isset($config[self::ALLOWED_CONTINUE])) { + $this->allowedContinue = (boolean)$config[self::ALLOWED_CONTINUE]; + } + $this->redirectURL = (string)$config[self::REDIRECT_URL]; + $this->pageText = $config[self::PAGE_TEXT]; + } + + public function process(&$request) + { + $listOfLoginsToRedirect = file_get_contents($this->URLWtithLogins); + if (empty($listOfLoginsToRedirect)) { + Logger::debug('perun:RedirectSomeUsers - List of logins is empty!'); + } + + $listOfLoginsToRedirect = explode("\n", $listOfLoginsToRedirect); + + if (!isset($request['Attributes'][$this->attributeIdentifier])) { + Logger::debug('perun:RedirectSomeUsers - User has not an attribute with identifier \''. + $this->attributeIdentifier . ' \'!'); + } + $userLogins = $request['Attributes'][$this->attributeIdentifier]; + + $redirectUser = false; + + foreach ($userLogins as $userLogin) { + if (in_array($userLogin, $listOfLoginsToRedirect)) { + $redirectUser = true; + continue; + } + } + + if (!$redirectUser) { + Logger::debug('perun:RedirectSomeUsers - Redirect is not required. Skipping to another process filter.'); + return; + } + + + $id = State::saveState($request, 'perun:redirectSomeUsers'); + $url = Module::getModuleURL('perun/redirect_some_users.php'); + $attributes = [ + 'StateId' => $id, + 'allowedContinue' => $this->allowedContinue, + 'redirectURL' => $this->redirectURL, + 'pageText' => $this->pageText + ]; + HTTP::redirectTrustedURL($url, $attributes); + } +} diff --git a/templates/redirect_some_users-tpl.php b/templates/redirect_some_users-tpl.php new file mode 100644 index 00000000..af728758 --- /dev/null +++ b/templates/redirect_some_users-tpl.php @@ -0,0 +1,54 @@ +data['header'] = ''; +$allowedContinue = $this->data['allowedContinue']; +$redirectURL = $this->data['redirectURL']; +$pageText = $this->data['pageText']; +$this->includeAtTemplateBase('includes/header.php'); + +?> + +
+ + +

t('{perun:perun:redirect_some_users-header}') ?>

+ +
+ +
+ + +
+ + ' . $this->t('{perun:perun:continue}') . ''; + + + echo "
"; + echo '
'. $this->t('{perun:perun:continue_to_service}') . ' + +
'; + } else { + echo '' . + $this->t('{perun:perun:continue}') . ''; + } + ?> + +
+ +includeAtTemplateBase('includes/footer.php'); diff --git a/www/redirect_some_users.php b/www/redirect_some_users.php new file mode 100644 index 00000000..eba9997e --- /dev/null +++ b/www/redirect_some_users.php @@ -0,0 +1,28 @@ +getLanguage(); + +$t = new Template($config, 'perun:redirect_some_users-tpl.php'); +$t->data['allowedContinue'] = $_REQUEST['allowedContinue']; +$t->data['redirectURL'] = $_REQUEST['redirectURL']; +$t->data['language'] = $language; + +if (isset($_REQUEST['pageText'][$language])) { + $t->data['pageText'] = $_REQUEST['pageText'][$language]; +} else { + $t->data['pageText'] = $_REQUEST['pageText']['en']; +} + + + +$t->show(); diff --git a/www/redirect_some_users_continue.php b/www/redirect_some_users_continue.php new file mode 100644 index 00000000..fc82ca6f --- /dev/null +++ b/www/redirect_some_users_continue.php @@ -0,0 +1,9 @@ +