From d35f1b9e5f145505e6231d2a28b1e2501594afca Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Wed, 2 Dec 2009 11:52:09 +0000 Subject: [PATCH] Add no-cookie page and helper function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2015 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Utilities.php | 23 +++++++++++++++++++++++ modules/core/dictionaries/no_cookie.php | 24 ++++++++++++++++++++++++ modules/core/templates/no_cookie.tpl.php | 22 ++++++++++++++++++++++ modules/core/www/no_cookie.php | 12 ++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 modules/core/dictionaries/no_cookie.php create mode 100644 modules/core/templates/no_cookie.tpl.php create mode 100644 modules/core/www/no_cookie.php diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 546d5d872..cf7d9921c 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -2199,6 +2199,29 @@ class SimpleSAML_Utilities { var_export($idpmetadata['entityid'], TRUE) . '.'); } + + /** + * Check for session cookie, and show missing-cookie page if it is missing. + * + * @param string|NULL $retryURL The URL the user should access to retry the operation. + */ + public static function checkCookie($retryURL = NULL) { + assert('is_string($retryURL) || is_null($retryURL)'); + + $session = SimpleSAML_Session::getInstance(); + if ($session->hasSessionCookie()) { + return; + } + + /* We didn't have a session cookie. Redirect to the no-cookie page. */ + + $url = SimpleSAML_Module::getModuleURL('core/no_cookie.php'); + if ($retryURL !== NULL) { + $url = SimpleSAML_Utilities::addURLParameter($url, array('retryURL' => $retryURL)); + } + SimpleSAML_Utilities::redirect($url); + } + } ?> \ No newline at end of file diff --git a/modules/core/dictionaries/no_cookie.php b/modules/core/dictionaries/no_cookie.php new file mode 100644 index 000000000..957917d38 --- /dev/null +++ b/modules/core/dictionaries/no_cookie.php @@ -0,0 +1,24 @@ +<?php + +/* + * Not yet in translation portal. + */ + +$lang = array( + 'header' => array ( + 'no' => 'Mangler informasjonskapsel', + 'en' => 'Missing cookie', + ), + 'description' => array ( + 'no' => 'Du ser ut til å ha deaktivert informasjonskapsler. Kontroller innstillingene i nettleseren din og prøv igjen.', + 'en' => 'You appear to have disabled cookies in your browser. Please check the settings in your browser, and try again.', + ), + 'retry' => array ( + 'no' => 'Prøv igjen', + 'en' => 'Retry', + ), + +); + + +?> \ No newline at end of file diff --git a/modules/core/templates/no_cookie.tpl.php b/modules/core/templates/no_cookie.tpl.php new file mode 100644 index 000000000..bec98bdee --- /dev/null +++ b/modules/core/templates/no_cookie.tpl.php @@ -0,0 +1,22 @@ +<?php + +assert('array_key_exists("retryURL", $this->data)'); +$retryURL = $this->data['retryURL']; + +$header = htmlspecialchars($this->t('{core:no_cookie:header}')); +$description = htmlspecialchars($this->t('{core:no_cookie:description}')); +$retry = htmlspecialchars($this->t('{core:no_cookie:retry}')); + +$this->data['header'] = $header; +$this->includeAtTemplateBase('includes/header.php'); + +echo('<h2>' . $header . '</h2>'); +echo('<p>' . $description . '</p>'); + +if ($retryURL !== NULL) { + echo('<ul>'); + echo('<li><a href="' . htmlspecialchars($retryURL) . '" id="retry">' . $retry . '</a></li>'); + echo('</ul>'); +} + +$this->includeAtTemplateBase('includes/footer.php'); diff --git a/modules/core/www/no_cookie.php b/modules/core/www/no_cookie.php new file mode 100644 index 000000000..211712d6d --- /dev/null +++ b/modules/core/www/no_cookie.php @@ -0,0 +1,12 @@ +<?php + +if (isset($_REQUEST['retryURL'])) { + $retryURL = (string)$_REQUEST['retryURL']; +} else { + $retryURL = NULL; +} + +$globalConfig = SimpleSAML_Configuration::getInstance(); +$t = new SimpleSAML_XHTML_Template($globalConfig, 'core:no_cookie.tpl.php'); +$t->data['retryURL'] = $retryURL; +$t->show(); -- GitLab