Example #1
0
/**
 * Appends an OpenID url to a user's account
 *
 * @param object $user
 * @param string $openid_url
 * @return boolean
 */
function openid_append_url($user, $openid_url)
{
    $config = get_config('auth/openid');
    $allow_append = $config->auth_openid_allow_muliple == 'true';
    $user = get_complete_user_data('id', $user->id);
    if (empty($user)) {
        logout_tmpuser_error(get_string('auth_openid_not_logged_in', 'auth_openid'));
        return false;
    }
    if (count_records('openid_urls', 'userid', $user->id) > 0 && !$allow_append) {
        logout_tmpuser_error(get_string('auth_openid_no_multiple', 'auth_openid'));
        return false;
    }
    if (openid_already_exists($openid_url)) {
        logout_tmpuser_error(get_string('auth_openid_url_exists', 'auth_openid', $openid_url));
        return false;
    }
    if ($user->auth == 'openid') {
        $record = new object();
        $record->userid = $user->id;
        $record->url = $openid_url;
        if (insert_record('openid_urls', $record) !== false) {
            return true;
        }
    }
    return false;
}
Example #2
0
/**
 * Checks if openid url already exists, outputs error;
 * Attempts to change user account to openid, outputs error on failure.
 * If global $openid_tmp_login is set logs out current temporary user.
 * Called from actions.php
 *
 * @param user object $user - the [potential] user to change to OpenID
 * @param string $url - the unique OpenID URL
 */
function openid_if_unique_change_account($user, $url)
{
    global $openid_tmp_login;
    if (openid_already_exists($url)) {
        logout_tmpuser_error(get_string('auth_openid_url_exists', 'auth_openid', $url));
    } else {
        if (!openid_change_user_account($user, $url, $openid_tmp_login)) {
            logout_tmpuser_error(get_string('auth_openid_login_error', 'auth_openid'));
        }
    }
}
Example #3
0
         $resp = $authplugin->process_response($_GET, true);
         if ($resp !== false) {
             $url = $resp->identity_url;
             $file = 'confirm_append.html';
         }
     } elseif ($confirm) {
         if (!confirm_sesskey()) {
             logout_tmpuser_error(get_string('auth_openid_bad_session_key', 'auth_openid'), true);
         } else {
             openid_append_url($USER, $url);
         }
     } elseif ($cancel) {
         logout_tmpuser_error(get_string('action_cancelled', 'auth_openid'));
     } elseif ($url != null) {
         if (openid_already_exists($url)) {
             logout_tmpuser_error(get_string('auth_openid_url_exists', 'auth_openid', $url));
         } else {
             $params['openid_action'] = 'append';
             $authplugin->do_request($reqinfo, $CFG->wwwroot . '/auth/openid/actions.php', $params);
         }
     }
     break;
     // Delete OpenIDs from an account
 // Delete OpenIDs from an account
 case 'delete':
     // Check if any urls selected for delete
     if (sizeof($delete_urls) < 1) {
         print_error('no_urls_selected', 'auth_openid');
     }
     // Prevent users from deleting all their OpenIDs!
     if (sizeof($delete_urls) >= count_records('openid_urls', 'userid', $USER->id)) {