Browse Source

Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into 1.9.x

Yannick Warnier 11 years ago
parent
commit
8ceb6a302e
2 changed files with 38 additions and 23 deletions
  1. 21 6
      main/auth/cas/authcas.php
  2. 17 17
      main/inc/local.inc.php

+ 21 - 6
main/auth/cas/authcas.php

@@ -160,13 +160,28 @@ function cas_is_authenticated()
 }
 
 /**
-* Logs out the user of the cas 
-* The user MUST be logged in with cas to use this function 
-**/ 
-function cas_logout()
+ * Logs out the user of the cas
+ * The user MUST be logged in with cas to use this function
+ *
+ * @param $uinfo array user info (not needed)
+ * @param $location string redirect url
+ *
+ * @see online_logout()
+ */
+function cas_logout($uinfo=null, $location=null)
 {
-	//phpCAS::logoutWithRedirectService("fmc.univ-paris5.fr");		
-	phpCAS::logoutWithRedirectService(api_get_path(WEB_PATH));		
+    global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
+    global $PHPCAS_CLIENT;
+    if (!is_object($PHPCAS_CLIENT)) {
+        phpCAS::client($cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri);
+        phpCAS::setNoCasServerValidation();
+    }
+
+    if (!isset($location)) {
+        $location = api_get_path(WEB_PATH);
+    }
+
+    phpCAS::logoutWithRedirectService($location);
 }
 
 

+ 17 - 17
main/inc/local.inc.php

@@ -326,28 +326,28 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) {
 
                                 if ($my_user_is_admin === false) {
 
-                                    if (is_array($my_url_list) && count($my_url_list)>0 ) {
-                                        // the user have the permissions to enter at this site
-                                        if (in_array($current_access_url_id, $my_url_list)) {
-                                            ConditionalLogin::check_conditions($uData);
+                                    // the user have the permissions to enter at this site
+                                    if (is_array($my_url_list) && in_array($current_access_url_id, $my_url_list)) {
+                                        ConditionalLogin::check_conditions($uData);
 
-                                            $_user['user_id'] = $uData['user_id'];
-                                            $_user['status']  = $uData['status'];
-                                            Session::write('_user', $_user);
-                                            event_login();
-                                            $logging_in = true;
-                                        } else {
-                                            $loginFailed = true;
-                                            Session::write('loginFailed', '1');
-                                            Session::erase('_uid');
-                                            header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive');
-                                            exit;
-                                        }
+                                        $_user['user_id'] = $uData['user_id'];
+                                        $_user['status']  = $uData['status'];
+                                        Session::write('_user', $_user);
+                                        event_login();
+                                        $logging_in = true;
                                     } else {
                                         $loginFailed = true;
                                         Session::erase('_uid');
                                         Session::write('loginFailed', '1');
-                                        header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive');
+
+                                        // Fix cas redirection loop
+                                        // https://support.chamilo.org/issues/6124
+                                        $location = api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive';
+                                        if ($cas_login) {
+                                            cas_logout(null, $location);
+                                        } else {
+                                            header('Location: '.$location);
+                                        }
                                         exit;
                                     }
                                 } else { //Only admins of the "main" (first) Chamilo portal can login wherever they want