From 1fd623b4da5828e20b02de94a4cf1ab33b487e8c Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Fri, 30 Apr 2010 20:35:44 +0000
Subject: [PATCH] Handle CAS logouts.

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@72 20a16fea-79d4-4915-8869-1ea9d5ebf173
---
 sites/all/modules/unl/unl_cas.module | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/sites/all/modules/unl/unl_cas.module b/sites/all/modules/unl/unl_cas.module
index 0a0a5723..eee6366c 100644
--- a/sites/all/modules/unl/unl_cas.module
+++ b/sites/all/modules/unl/unl_cas.module
@@ -5,24 +5,29 @@ function unl_cas_init()
     require_once dirname(__FILE__) . '/lib/CAS/CAS.php';
     phpCAS::client(CAS_VERSION_2_0,'login.unl.edu',443,'/cas');
     phpCAS::setNoCasServerValidation();
+    phpCAS::handleLogoutRequests();
     
     if (!array_key_exists('last_sso_check', $_SESSION)) {
         $_SESSION['unl']['last_sso_check'] = 0;
     }
     
+    $auth = FALSE;
     if (array_key_exists('unl_sso', $_COOKIE)) {
         $auth = phpCAS::checkAuthentication();
-        if ($auth) {
-            $username = phpCAS::getUser();
-            $user = user_load_by_name($username);
-            if (!$user) {
-                $user = unl_cas_import_user($username);
-            }
-            if ($GLOBALS['user']->uid != $user->uid) {
-                $GLOBALS['user'] = $user;
-                user_login_finalize();
-            }
+    }
+    if ($auth) {
+        $username = phpCAS::getUser();
+        $user = user_load_by_name($username);
+        if (!$user) {
+            $user = unl_cas_import_user($username);
+        }
+        if ($GLOBALS['user']->uid != $user->uid) {
+            $GLOBALS['user'] = $user;
+            user_login_finalize();
         }
+    } else if (!user_is_anonymous()) {
+        $GLOBALS['user'] = drupal_anonymous_user();
+        user_login_finalize();
     }
 }
 
-- 
GitLab