Esempio n. 1
0
require_once dirname(dirname(dirname(__FILE__))) . '/lib/lib.php';
// get module configuration
$config = find_plugin_settings('cas_auth');
$NetUsername = authCAS($config);
// get user details out of LDAP.
//$attr = cas_ldapSearch($NetUsername);
$casUser = cas_mysqlSearch($NetUsername);
if (!empty($casUser->username)) {
    $username = $casUser->username;
} else {
    $username = $NetUsername;
}
//$username = empty($username) ? $username : str_replace(".", "",$username);
$user = get_user_by_username($username);
if (!$user) {
    $user_guid = cas_insertUser($username, $casUser, $config);
    $user = get_user_by_username($username);
    $result = cas_do_login($user, false);
} else {
    $result = cas_do_login($user, false);
}
if ($result) {
    system_message(elgg_echo('loginok'));
    if ($_SESSION['last_forward_from']) {
        $forward_url = $_SESSION['last_forward_from'];
        $_SESSION['last_forward_from'] = "";
        forward($forward_url);
    } else {
        if (elgg_is_admin_logged_in() && !datalist_get('first_admin_login')) {
            system_message(elgg_echo('firstadminlogininstructions'));
            datalist_set('first_admin_login', time());
Esempio n. 2
0
    $username = $ldap_attributes['textUid'];
} else {
    $username = $ldap_username;
}
// elgg usernames cannot have periods
$clean_username = str_replace(".", "", $username);
// grab Elgg user, show hidden to find disabled users
$show_hidden = access_get_show_hidden_status();
access_show_hidden_entities(true);
$user = get_user_by_username($clean_username);
access_show_hidden_entities($show_hidden);
// if no user found in elgg, insert a new user
if (!$user) {
    // insert user
    // returns guid or false
    $user_guid = cas_insertUser($clean_username, $ldap_attributes, $plugin_settings);
    if (!$user_guid) {
        // error inserting user
        register_error(elgg_echo('cas:errors:cantinsert'));
    }
    // retrieve elgg user object
    $user = get_user_by_username($clean_username);
    if (!$user) {
        // error inserting user
        register_error(elgg_echo('cas:errors:cantinsert'));
    }
    // now log that user into Elgg
    $result = login($user, true);
} else {
    if ($user->isEnabled() && !$user->isBanned()) {
        // login the user