Skip to content
Snippets Groups Projects
Commit b5ddb024 authored by Tim Steiner's avatar Tim Steiner
Browse files

[gh-141] Merging from testing into staging

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@734 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent a92ccf2c
No related branches found
No related tags found
No related merge requests found
...@@ -8,23 +8,20 @@ function unl_cas_enable() { ...@@ -8,23 +8,20 @@ function unl_cas_enable() {
} }
function unl_cas_init() { function unl_cas_init() {
drupal_session_start();
// If no one is claiming to be logged in while no one is actually logged in, we don't need CAS.
if (isset($_SESSION['unl_cas']['current_path'])) { if (!array_key_exists('unl_sso', $_COOKIE) && user_is_anonymous()) {
$_SESSION['unl_cas']['previous_path'] = $_SESSION['unl_cas']['current_path']; return;
} }
$_SESSION['unl_cas']['current_path'] = request_path();
$cas = unl_cas_get_adapter(); // The current request is to the validation URL, we don't want to redirect while a login is pending.
if (request_path() == 'user/cas') {
// If this is a request to the validation URL, or if the CAS ticket is not expired, don't redirect.
if (request_path() == 'user/cas' || !$cas->isTicketExpired()) {
return; return;
} }
// At this point, we know the ticket has expired. // If the current user's CAS ticket is expired or doesn't exist, renew their CAS session.
// If we think a user is supposed to be logged in, attempt to renew the service ticket. $cas = unl_cas_get_adapter();
if (array_key_exists('unl_sso', $_COOKIE) || !user_is_anonymous()) { if ($cas->isTicketExpired()) {
$_SESSION['unl_cas']['return_path'] = $_SESSION['unl_cas']['current_path'];
$cas->setGateway(); $cas->setGateway();
drupal_goto($cas->getLoginUrl()); drupal_goto($cas->getLoginUrl());
} }
...@@ -34,13 +31,16 @@ function unl_cas_init() { ...@@ -34,13 +31,16 @@ function unl_cas_init() {
* @return Unl_Cas * @return Unl_Cas
*/ */
function unl_cas_get_adapter() { function unl_cas_get_adapter() {
// Start the session because if drupal doesn't then Zend_Session will.
drupal_session_start();
static $adapter; static $adapter;
if (!$adapter) { if (!$adapter) {
if (variable_get('https', FALSE)) { if (variable_get('https', FALSE)) {
$url = url('user/cas', array('absolute' => TRUE, 'https' => TRUE)); $url = url('user/cas', array('absolute' => TRUE, 'query' => drupal_get_destination(), 'https' => TRUE));
} else { } else {
$url = url('user/cas', array('absolute' => TRUE)); $url = url('user/cas', array('absolute' => TRUE, 'query' => drupal_get_destination()));
} }
unset($_GET['destination']);
$adapter = new Unl_Cas($url, 'https://login.unl.edu/cas'); $adapter = new Unl_Cas($url, 'https://login.unl.edu/cas');
} }
return $adapter; return $adapter;
...@@ -83,6 +83,7 @@ function unl_cas_menu_alter(&$items) { ...@@ -83,6 +83,7 @@ function unl_cas_menu_alter(&$items) {
} }
function unl_cas_validate() { function unl_cas_validate() {
drupal_session_start();
$cas = unl_cas_get_adapter(); $cas = unl_cas_get_adapter();
if (array_key_exists('logoutRequest', $_POST)) { if (array_key_exists('logoutRequest', $_POST)) {
...@@ -108,22 +109,13 @@ function unl_cas_validate() { ...@@ -108,22 +109,13 @@ function unl_cas_validate() {
setcookie('unl_sso', 'fake', time() - 60 * 60 * 24, '/', '.unl.edu'); setcookie('unl_sso', 'fake', time() - 60 * 60 * 24, '/', '.unl.edu');
} }
if (isset($_SESSION['unl_cas']['return_path'])) { $destination = drupal_get_destination();
drupal_goto($_SESSION['unl_cas']['return_path']); unset($_GET['destination']);
} else { drupal_goto($destination['destination']);
drupal_goto('user');
}
} }
function unl_cas_form_alter(&$form, $form_state, $form_id) { function unl_cas_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login') { if ($form_id == 'user_login') {
if (isset($_GET['destination'])) {
$_SESSION['unl_cas']['return_path'] = $_GET['destination'];
unset($_GET['destination']);
}
else if (isset($_SESSION['unl_cas']['previous_path'])) {
$_SESSION['unl_cas']['return_path'] = $_SESSION['unl_cas']['previous_path'];
}
$cas = unl_cas_get_adapter(); $cas = unl_cas_get_adapter();
drupal_goto($cas->getLoginUrl()); drupal_goto($cas->getLoginUrl());
} }
......
...@@ -46,7 +46,7 @@ $t->head .= PHP_EOL ...@@ -46,7 +46,7 @@ $t->head .= PHP_EOL
. $scripts . PHP_EOL . $scripts . PHP_EOL
. '<link href="' . url('<front>', array('absolute' => TRUE)) . '" rel="home" />' . PHP_EOL . '<link href="' . url('<front>', array('absolute' => TRUE)) . '" rel="home" />' . PHP_EOL
. '<link rel="logout" href="user/logout" />' . PHP_EOL . '<link rel="logout" href="user/logout" />' . PHP_EOL
. '<link rel="login" href="user" />' . PHP_EOL . '<link rel="login" href="' . url('user', array('query' => drupal_get_destination())) . '" />' . PHP_EOL
. theme_get_setting('head_html') . PHP_EOL . theme_get_setting('head_html') . PHP_EOL
; ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment