You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							96 lines
						
					
					
						
							2.4 KiB
						
					
					
				
			
		
		
	
	
							96 lines
						
					
					
						
							2.4 KiB
						
					
					
				<?php
 | 
						|
 | 
						|
use \ChamiloSession as Session;
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * A Chamilo user session. Used as there is no session object so far provided by the core API.
 | 
						|
 * Should be moved to the core library.Prefixed by Shibboleth to avoid name clashes.
 | 
						|
 *
 | 
						|
 * @license see /license.txt
 | 
						|
 * @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
 | 
						|
 */
 | 
						|
class ShibbolethSession
 | 
						|
{
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return ShibbolethSession
 | 
						|
     */
 | 
						|
    public static function instance()
 | 
						|
    {
 | 
						|
        static $result = false;
 | 
						|
        if (empty($result)) {
 | 
						|
            $result = new self();
 | 
						|
        }
 | 
						|
        return $result;
 | 
						|
    }
 | 
						|
 | 
						|
    function is_logged_in()
 | 
						|
    {
 | 
						|
        return isset($_SESSION['_user']['user_id']);
 | 
						|
    }
 | 
						|
 | 
						|
    function user()
 | 
						|
    {
 | 
						|
        return $_SESSION['_user'];
 | 
						|
    }
 | 
						|
 | 
						|
    function logout()
 | 
						|
    {
 | 
						|
        $_SESSION['_user'] = array();
 | 
						|
        online_logout(null, false);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Create a Shibboleth session for 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)
 | 
						|
    {
 | 
						|
        /* 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;
 | 
						|
        }
 | 
						|
 | 
						|
        $this->logout();
 | 
						|
 | 
						|
        Chamilo::session()->start();
 | 
						|
        Session::write('_uid', $_uid);
 | 
						|
 | 
						|
        global $_user;
 | 
						|
        $_user = (array) $user;
 | 
						|
 | 
						|
        $_SESSION['_user'] = $_user;
 | 
						|
        $_SESSION['_user']['user_id'] = $_uid;
 | 
						|
        $_SESSION['noredirection'] = true;
 | 
						|
 | 
						|
        //must be called before 'init_local.inc.php'
 | 
						|
        event_login();
 | 
						|
 | 
						|
        //used in 'init_local.inc.php' this is BAD but and should be changed
 | 
						|
        $loginFailed = false;
 | 
						|
        $uidReset = true;
 | 
						|
 | 
						|
        $gidReset = true;
 | 
						|
        $cidReset = false; //FALSE !!      
 | 
						|
 | 
						|
        $mainDbName = Database :: get_main_database();
 | 
						|
        $includePath = api_get_path(INCLUDE_PATH);
 | 
						|
 | 
						|
        $no_redirection = true;
 | 
						|
        require("$includePath/local.inc.php");
 | 
						|
 | 
						|
        return $_user;
 | 
						|
    }
 | 
						|
 | 
						|
} |