diff --git a/custompages/loggedout.php b/custompages/loggedout.php new file mode 100644 index 0000000000..2b45579c46 --- /dev/null +++ b/custompages/loggedout.php @@ -0,0 +1,57 @@ + + + + + Custompage - logged out + + + + + + + + + + + +
+ background +
+
+ + +
+
+ You have been logged out. +
+
+ Go to your portal + +
+ + diff --git a/index.php b/index.php index 72c46bbc49..cc0845bd19 100644 --- a/index.php +++ b/index.php @@ -79,9 +79,17 @@ if (api_get_setting('allow_terms_conditions') == 'true') { unset($_SESSION['info_current_user']); } //If we are not logged in and customapages activated -if (!api_get_user_id() && api_get_setting('use_custom_pages') == 'true' ){ +if (!api_get_user_id() && api_get_setting('use_custom_pages') == 'true' ) +{ require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; - CustomPages::displayPage('index-unlogged'); + if(Request::get('loggedout')) + { + CustomPages::displayPage('loggedout'); + } + else + { + CustomPages::displayPage('index-unlogged'); + } } /** diff --git a/main/auth/shibboleth/app/controller/shibboleth_controller.class.php b/main/auth/shibboleth/app/controller/shibboleth_controller.class.php index 00a2d35f50..6624e31f27 100644 --- a/main/auth/shibboleth/app/controller/shibboleth_controller.class.php +++ b/main/auth/shibboleth/app/controller/shibboleth_controller.class.php @@ -31,7 +31,7 @@ class ShibbolethController if (Shibboleth::session()->is_logged_in()) { - Shibboleth::redirect(); + Redirect::home(); } $user = Shibboleth::store()->get_user(); diff --git a/main/auth/shibboleth/app/shibboleth.class.php b/main/auth/shibboleth/app/shibboleth.class.php index 186443c8a4..5bf9ad91fb 100644 --- a/main/auth/shibboleth/app/shibboleth.class.php +++ b/main/auth/shibboleth/app/shibboleth.class.php @@ -10,6 +10,7 @@ class Shibboleth { + const NAME = 'shibboleth'; const UNKNOWN_STATUS = -1; const TEACHER_STATUS = 1; const STUDENT_STATUS = 5; @@ -125,17 +126,10 @@ class Shibboleth $first_slash_pos = strpos($rootWeb, '/', 8); $rootWeb_wo_uri = substr($rootWeb, 0, $first_slash_pos); $url = $rootWeb_wo_uri . $course_url . '_stop'; - header("Location: $url"); + Redirect::go($url); } } - else - { - $_SESSION['request_uri']; - } - - $url = api_get_path('WEB_PATH') . $url; - header("Location: $url"); - die; + Redirect::go(); } /** @@ -152,6 +146,7 @@ class Shibboleth $user = User::store()->get_by_shibboleth_id($shibb_user->unique_id); if (empty($user)) { + $shibb_user->auth_source == self::NAME; return User::create($shibb_user)->save(); } @@ -163,6 +158,7 @@ class Shibboleth { $user->{$key} = $shibb_user->{$key}; } + $user->auth_source == self::NAME; } $user->save(); return $result; diff --git a/main/auth/shibboleth/app/view/shibboleth_display.class.php b/main/auth/shibboleth/app/view/shibboleth_display.class.php index 2ba00058cb..138e6f21dc 100644 --- a/main/auth/shibboleth/app/view/shibboleth_display.class.php +++ b/main/auth/shibboleth/app/view/shibboleth_display.class.php @@ -25,8 +25,6 @@ class ShibbolethDisplay public function error_page($message) { - $include_path = api_get_path(INCLUDE_PATH); - require("$include_path/local.inc.php"); $page_title = get_lang('page_title'); Display :: display_header($page_title); @@ -37,8 +35,6 @@ class ShibbolethDisplay public function message_page($message, $title = '') { - $include_path = api_get_path(INCLUDE_PATH); - require("$include_path/local.inc.php"); $title = $title ? $title : get_lang('page_title'); Display :: display_header($title); @@ -49,8 +45,6 @@ class ShibbolethDisplay public function page($content, $title = '') { - $include_path = api_get_path(INCLUDE_PATH); - require("$include_path/local.inc.php"); $title = $title ? $title : get_lang('page_title'); Display :: display_header($title); diff --git a/main/auth/shibboleth/init.php b/main/auth/shibboleth/init.php index a26db19bd6..30df67252d 100644 --- a/main/auth/shibboleth/init.php +++ b/main/auth/shibboleth/init.php @@ -9,11 +9,12 @@ */ $__dir = dirname(__FILE__) . '/'; +$no_redirection = true; //no redirection in global. include_once($__dir . '/../../inc/global.inc.php'); -require_once $__dir . 'app/lib/shibboleth_config.class.php'; -require_once $__dir . 'app/lib/shibboleth_session.class.php'; -require_once $__dir . 'app/lib/store.class.php'; +require_once $__dir . 'lib/shibboleth_config.class.php'; +require_once $__dir . 'lib/shibboleth_session.class.php'; +require_once $__dir . 'lib/store.class.php'; require_once $__dir . 'app/controller/shibboleth_controller.class.php'; require_once $__dir . 'app/model/shibboleth_store.class.php'; require_once $__dir . 'app/model/shibboleth_user.class.php'; diff --git a/main/auth/shibboleth/app/lib/model.class.php b/main/auth/shibboleth/lib/model.class.php similarity index 100% rename from main/auth/shibboleth/app/lib/model.class.php rename to main/auth/shibboleth/lib/model.class.php diff --git a/main/auth/shibboleth/app/lib/scaffolder/scaffolder.class.php b/main/auth/shibboleth/lib/scaffolder/scaffolder.class.php similarity index 100% rename from main/auth/shibboleth/app/lib/scaffolder/scaffolder.class.php rename to main/auth/shibboleth/lib/scaffolder/scaffolder.class.php diff --git a/main/auth/shibboleth/app/lib/scaffolder/template/default.php b/main/auth/shibboleth/lib/scaffolder/template/default.php similarity index 100% rename from main/auth/shibboleth/app/lib/scaffolder/template/default.php rename to main/auth/shibboleth/lib/scaffolder/template/default.php diff --git a/main/auth/shibboleth/app/lib/scaffolder/template/model.php b/main/auth/shibboleth/lib/scaffolder/template/model.php similarity index 100% rename from main/auth/shibboleth/app/lib/scaffolder/template/model.php rename to main/auth/shibboleth/lib/scaffolder/template/model.php diff --git a/main/auth/shibboleth/app/lib/scaffolder/template/public.php b/main/auth/shibboleth/lib/scaffolder/template/public.php similarity index 100% rename from main/auth/shibboleth/app/lib/scaffolder/template/public.php rename to main/auth/shibboleth/lib/scaffolder/template/public.php diff --git a/main/auth/shibboleth/app/lib/shibboleth_config.class.php b/main/auth/shibboleth/lib/shibboleth_config.class.php similarity index 100% rename from main/auth/shibboleth/app/lib/shibboleth_config.class.php rename to main/auth/shibboleth/lib/shibboleth_config.class.php diff --git a/main/auth/shibboleth/app/lib/shibboleth_session.class.php b/main/auth/shibboleth/lib/shibboleth_session.class.php similarity index 74% rename from main/auth/shibboleth/app/lib/shibboleth_session.class.php rename to main/auth/shibboleth/lib/shibboleth_session.class.php index 59fcde9b3b..2c964df6af 100644 --- a/main/auth/shibboleth/app/lib/shibboleth_session.class.php +++ b/main/auth/shibboleth/lib/shibboleth_session.class.php @@ -44,12 +44,20 @@ class ShibbolethSession /** * Create a Shibboleth session for the user ID * - * @param string $_uid - The user ID + * @param string $uid - The user ID * @return $_user (array) - The user infos array created when the user logs in */ - function login($_uid) + function login($uid) { - $user = User::store()->get_by_user_id($_uid); + /* This must be set for local.inc.php to register correctly the global variables in session + * This is BAD. Logic should be migrated into a function and stop relying on global variables. + */ + global $_uid, $is_allowedCreateCourse, $is_platformAdmin, $_real_cid, $_courseUser, $is_courseAdmin; + global $is_courseMember, $is_courseTutor, $is_courseCoach, $is_allowed_in_course, $is_sessionAdmin, $_gid; + $_uid = $uid; + + //is_allowedCreateCourse + $user = User::store()->get_by_user_id($uid); if (empty($user)) { return; @@ -80,11 +88,7 @@ class ShibbolethSession $mainDbName = Database :: get_main_database(); $includePath = api_get_path(INCLUDE_PATH); - global $is_platformAdmin; - /* This must be set for local.inc.php to set up correctly the platform admin - * This is BAD. - */ - + $no_redirection = true; require("$includePath/local.inc.php"); diff --git a/main/auth/shibboleth/app/lib/store.class.php b/main/auth/shibboleth/lib/store.class.php similarity index 100% rename from main/auth/shibboleth/app/lib/store.class.php rename to main/auth/shibboleth/lib/store.class.php diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index c5441f6914..8ebb1d3a02 100644 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -92,6 +92,9 @@ ini_set('include_path', api_create_include_path_setting()); ini_set('auto_detect_line_endings', '1'); // Include the libraries that are necessary everywhere +require_once $lib_path.'autoload.class.php'; +Autoload::register(); + require_once $lib_path.'database.lib.php'; require_once $lib_path.'template.lib.php'; require_once $lib_path.'display.lib.php'; diff --git a/main/inc/lib/autoload.class.php b/main/inc/lib/autoload.class.php new file mode 100644 index 0000000000..123617ab12 --- /dev/null +++ b/main/inc/lib/autoload.class.php @@ -0,0 +1,60 @@ + for the Univesity of Geneva + */ +class Autoload +{ + + /** + * Register the Chamilo autoloader on the stack. + */ + static public function register() + { + $f = array(new self, 'load'); + spl_autoload_register($f); + } + + static public function map() + { + static $result = false; + + if ($result) + { + return $result; + } + + $dir = dirname(__FILE__); + + $result = array(); + $result['Redirect'] = $dir . '/redirect.class.php'; + $result['Request'] = $dir . '/request.class.php'; + return $result; + } + + /** + * Handles autoloading of classes. + * + * @param string $class_name A class name. + * + * @return boolean returns true if the class has been loaded + */ + public function load($class_name) + { + $map = self::map(); + if (isset($map[$class_name])) + { + $path = $map[$class_name]; + require_once $path; + return true; + } + else + { + return false; + } + } + +} diff --git a/main/inc/lib/redirect.class.php b/main/inc/lib/redirect.class.php new file mode 100644 index 0000000000..468cb0df0f --- /dev/null +++ b/main/inc/lib/redirect.class.php @@ -0,0 +1,77 @@ + for the Univesity of Geneva + */ +class Redirect +{ + + static function www() + { + static $result = false; + if (empty($result)) + { + $result = api_get_path('WEB_PATH'); + } + return $result; + } + + static function go($url = '') + { + if (empty($url)) + { + Redirect::session_request_uri(); + $www = self::www(); + self::navigate($www); + } + + $is_full_uri = (strpos($url, 'http') === 0); + if ($is_full_uri) + { + self::navigate($url); + } + + $url = self::www() . $url; + self::navigate($url); + } + + /** + * Redirect to the session "request uri" if it exists. + */ + static function session_request_uri() + { +// if (api_is_anonymous()) +// { +// return; +// } + $url = isset($_SESSION['request_uri']) ? $_SESSION['request_uri'] : ''; + unset($_SESSION['request_uri']); + if ($url) + { + self::navigate($url); + } + } + + static function home() + { + $www = self::www(); + self::navigate($www); + } + + static function user_home() + { + $www = self::www(); + self::navigate("$www/user_portal.php"); + } + + protected static function navigate($url) + { + session_write_close(); //should not be neeeded + header("Location: $url"); + exit; + } + +} \ No newline at end of file diff --git a/main/inc/lib/request.class.php b/main/inc/lib/request.class.php new file mode 100644 index 0000000000..86a9de5aaa --- /dev/null +++ b/main/inc/lib/request.class.php @@ -0,0 +1,37 @@ + for the Univesity of Geneva + */ +class Request +{ + + public static function get($key, $default = null) + { + return isset($_GET[$key]) ? isset($_GET[$key]) : $default; + } + + public static function post($key, $default = null) + { + return isset($_POST[$key]) ? isset($_POST[$key]) : $default; + } + + static function server($key, $default = null) + { + return isset($_SERVER[$key]) ? isset($_SERVER[$key]) : $default; + } + + static function file($key, $default = null) + { + return isset($_FILES[$key]) ? isset($_FILES[$key]) : $default; + } + + static function environment($key, $default = null) + { + return isset($_ENV[$key]) ? isset($_ENV[$key]) : $default; + } + +} \ No newline at end of file diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 91fda7f0a8..7fd3ca33d2 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -158,6 +158,7 @@ class IndexManager { } exit_of_chat($uid); api_session_destroy(); + $query_string = $query_string ? "$query_string&loggedout=true" : '?loggedout=true'; header("Location: index.php$query_string"); exit(); } @@ -242,12 +243,12 @@ class IndexManager { if ($show_menu) { $html .= '