Ejemplo n.º 1
0
/**
 * This function connect to facebook and retrieves the user info
 * If user does not exist in chamilo, it creates it and logs in
 * If user already exists, it updates his info
 */
function facebookConnect()
{
    global $facebook_config;
    global $helper;
    try {
        $helper = new FacebookRedirectLoginHelper($facebook_config['return_url']);
        $session = $helper->getSessionFromRedirect();
        // see if we have a session
        if (isset($session)) {
            // graph api request for user data
            $request = new FacebookRequest($session, 'GET', '/me');
            $response = $request->execute();
            // get response
            $graphObject = $response->getGraphObject();
            $username = changeToValidChamiloLogin($graphObject->getProperty('email'));
            $email = $graphObject->getProperty('email');
            $locale = $graphObject->getProperty('locale');
            $language = facebookPluginGetLanguage($locale);
            if (!$language) {
                $language = 'en_US';
            }
            //Checks if user already exists in chamilo
            $u = array('firstname' => $graphObject->getProperty('first_name'), 'lastname' => $graphObject->getProperty('last_name'), 'status' => STUDENT, 'email' => $graphObject->getProperty('email'), 'username' => $username, 'language' => $language, 'password' => 'facebook', 'auth_source' => 'facebook', 'extra' => array());
            $chamiloUinfo = api_get_user_info_from_email($email);
            if ($chamiloUinfo === false) {
                // we have to create the user
                $chamilo_uid = external_add_user($u);
                if ($chamilo_uid !== false) {
                    $_user['user_id'] = $chamilo_uid;
                    $_user['uidReset'] = true;
                    $_SESSION['_user'] = $_user;
                    header('Location:' . api_get_path(WEB_PATH));
                    exit;
                } else {
                    return false;
                }
            } else {
                // User already exists, update info and login
                $chamilo_uid = $chamiloUinfo['user_id'];
                $u['user_id'] = $chamilo_uid;
                external_update_user($u);
                $_user['user_id'] = $chamilo_uid;
                $_user['uidReset'] = true;
                $_SESSION['_user'] = $_user;
                header('Location:' . api_get_path(WEB_PATH));
                exit;
            }
        }
    } catch (FacebookRequestException $ex) {
        echo $ex;
    } catch (Exception $ex) {
        // When validation fails or other local issues
    }
}
Ejemplo n.º 2
0
/**
 * This function connect to facebook and retrieves the user info
 * If user does not exist in chamilo, it creates it and logs in
 * If user already exists, it updates his info
 * */
function facebook_connect()
{
    global $facebook;
    // See if there is a user from a cookie
    $user = $facebook->getUser();
    if ($user) {
        try {
            //Gets facebook user info
            $fu = $facebook->api('/me');
            $username = $fu['username'];
            if (api_get_setting('login_is_email') == 'true' || empty($fu['username'])) {
                $username = change_to_valid_chamilo_login($fu['email']);
            }
            //Checks if user already exists in chamilo
            $u = array('firstname' => $fu['first_name'], 'lastname' => $fu['last_name'], 'status' => STUDENT, 'email' => $fu['email'], 'username' => $username, 'language' => 'french', 'password' => DEFAULT_PASSWORD, 'auth_source' => 'facebook', 'extra' => array());
            $cu = api_get_user_info_from_username($username);
            $chamilo_uinfo = api_get_user_info_from_username($username);
            if ($chamilo_uinfo === false) {
                //we have to create the user
                $chamilo_uid = external_add_user($u);
                if ($chamilo_uid !== false) {
                    $_user['user_id'] = $chamilo_uid;
                    $_user['uidReset'] = true;
                    $_SESSION['_user'] = $_user;
                    header('Location:' . api_get_path(WEB_PATH));
                    exit;
                } else {
                    return false;
                }
            } else {
                //User already exists, update info and login
                $chamilo_uid = $chamilo_uinfo['user_id'];
                $u['user_id'] = $chamilo_uid;
                external_update_user($u);
                $_user['user_id'] = $chamilo_uid;
                $_user['uidReset'] = true;
                $_SESSION['_user'] = $_user;
                header('Location:' . api_get_path(WEB_PATH));
                exit;
            }
        } catch (FacebookApiException $e) {
            echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
            $user = null;
        }
    }
}
Ejemplo n.º 3
0
require_once dirname(__FILE__) . '/functions.inc.php';
//MAIN CODE
//$uData variable is set in local.inc.php
$user = api_get_user_info($uData['user_id']);
$new_user = external_get_user_info($login);
$user['firstname'] = $new_user['firstname'];
$user['lastname'] = $new_user['lastname'];
$user['status'] = $new_user['status'];
$user['admin'] = $new_user['admin'];
$user['email'] = $new_user['email'];
$user['username'] = $new_user['username'];
$user['profile_link'] = $new_user['profile_link'];
$user['worldwide_bu'] = $new_user['worldwide_bu'];
$user['manager'] = $new_user['manager'];
$user['country_bu'] = $new_user['country_bu'];
$user['extra'] = $new_user['extra'];
if ($new_user !== false) {
    //User can login
    external_update_user($user);
    $loginFailed = false;
    $_user['user_id'] = $user['user_id'];
    $_user['uidReset'] = true;
    $uidReset = true;
    Session::write('_user', $_user);
} else {
    //User cannot login
    $loginFailed = true;
    Session::erase('_uid');
    header('Location: ' . api_get_path(WEB_PATH) . 'index.php?loginFailed=1&error=user_password_incorrect');
    exit;
}
Ejemplo n.º 4
0
 *
 * */
use ChamiloSession as Session;
require_once dirname(__FILE__) . '/ldap.inc.php';
require_once dirname(__FILE__) . '/functions.inc.php';
error_log('Entering login.ldap.php');
$ldap_user = extldap_authenticate($login, $password);
if ($ldap_user !== false) {
    error_log('extldap_authenticate works');
    $chamilo_user = extldap_get_chamilo_user($ldap_user);
    //userid is not on the ldap, we have to use $uData variable from local.inc.php
    $chamilo_user['user_id'] = $uData['user_id'];
    error_log("chamilo_user found user_id: {$uData['user_id']}");
    //Update user info
    if (isset($extldap_config['update_userinfo']) && $extldap_config['update_userinfo']) {
        external_update_user($chamilo_user);
        error_log("Calling external_update_user");
    }
    $loginFailed = false;
    $_user['user_id'] = $chamilo_user['user_id'];
    $_user['status'] = isset($chamilo_user['status']) ? $chamilo_user['status'] : 5;
    $_user['uidReset'] = true;
    Session::write('_user', $_user);
    $uidReset = true;
    $logging_in = true;
    event_login();
    error_log("Calling event_login");
} else {
    error_log('extldap_authenticate error');
    $loginFailed = true;
    $uidReset = false;