/** * 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')); } } }
// We need to print a confirmation message before proceeding $resp = $authplugin->process_response($_GET, true); if ($resp !== false) { $url = $resp->identity_url; $file = 'confirm_append.html'; } } elseif ($confirm) { if (!confirm_sesskey()) { error('Bad Session Key'); } else { openid_append_url($USER, $url); } } elseif ($cancel) { error(get_string('action_cancelled', 'auth_openid')); } elseif ($url != null) { if (openid_already_exists($url)) { error(get_string('auth_openid_url_exists', 'auth_openid', $url)); } else { $params['openid_action'] = 'append'; $authplugin->do_request(false, $CFG->wwwroot . '/auth/openid/actions.php', $params); } } break; // Delete OpenIDs from an account // Delete OpenIDs from an account case 'delete': // Prevent users from deleting all their OpenIDs! if (sizeof($delete_urls) >= count_records('openid_urls', 'userid', $USER->id)) { error(get_string('cannot_delete_all', 'auth_openid')); } if ($confirm && is_array($delete_urls)) {
/** * 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; }