Пример #1
0
/**
 * Action method for completing the 'login' action.  This action is used when a user is logging in from
 * wp-login.php.
 *
 * @param string $identity_url verified OpenID URL
 */
function openid_finish_login($identity_url, $action) {
	if ($action != 'login') return;
		
	// create new user account if appropriate
	$user_id = get_user_by_openid($identity_url);
	if ( $identity_url && !$user_id && get_option('users_can_register') ) {
		$user_data =& openid_get_user_data($identity_url);
		openid_create_new_user($identity_url, $user_data);
	}
	
	// return to wp-login page
	$url = get_option('siteurl') . '/wp-login.php';
	if (empty($identity_url)) {
		$url = add_query_arg('openid_error', openid_message(), $url);
	}

	$url = add_query_arg( array( 
		'finish_openid' => 1, 
		'identity_url' => urlencode($identity_url), 
		'redirect_to' => $_SESSION['openid_finish_url'],
		'_wpnonce' => wp_create_nonce('openid_login_' . md5($identity_url)), 
	), $url);
		
	wp_safe_redirect($url);
	exit;
}
Пример #2
0
/**
 * Action method for completing the 'login' action.  This action is used when a user is logging in from
 * wp-login.php.
 *
 * @param string $identity_url verified OpenID URL
 */
function openid_finish_login($identity_url, $action)
{
    if ($action != 'login') {
        return;
    }
    if ($identity_url) {
        // create new user account if appropriate
        $user_id = get_user_by_openid($identity_url);
        $user_data = openid_get_user_data($identity_url);
        if (!$user_id) {
            if (get_option('users_can_register')) {
                // registration is enabled so create a new user
                openid_create_new_user($identity_url, $user_data);
            } else {
                // generate a error because it is not possible to create a new user
                openid_message(__('Unable to create a new user.', 'openid'));
                openid_status('error');
            }
        } else {
            do_action('openid_consumer_update_user_custom_data', $user_id, $user_data);
        }
    }
    // return to wp-login page
    $url = get_option('siteurl') . '/wp-login.php';
    $status = openid_status();
    $error = openid_message();
    if ($status == 'error' && !empty($error)) {
        $url = add_query_arg('openid_error', openid_message(), $url);
    }
    $url = add_query_arg(array('finish_openid' => 1, 'identity_url' => urlencode($identity_url), 'redirect_to' => $_SESSION['openid_finish_url'], '_wpnonce' => wp_create_nonce('openid_login_' . md5($identity_url))), $url);
    wp_safe_redirect($url);
    exit;
}
Пример #3
0
/**
 * Action method for completing the 'login' action.  This action is used when a user is logging in from
 * wp-login.php.
 *
 * @param string $identity_url verified OpenID URL
 */
function openid_finish_login($identity_url)
{
    if ($_REQUEST['action'] != 'login') {
        return;
    }
    $redirect_to = urldecode($_REQUEST['redirect_to']);
    if (empty($identity_url)) {
        $url = get_option('siteurl') . '/wp-login.php?openid_error=' . urlencode(openid_message());
        wp_safe_redirect($url);
        exit;
    }
    openid_set_current_user($identity_url);
    if (!is_user_logged_in()) {
        if (get_option('users_can_register')) {
            $user_data =& openid_get_user_data($identity_url);
            $user = openid_create_new_user($identity_url, $user_data);
            openid_set_current_user($user->ID);
        } else {
            // TODO - Start a registration loop in WPMU.
            $url = get_option('siteurl') . '/wp-login.php?registration_closed=1';
            wp_safe_redirect($url);
            exit;
        }
    }
    if (empty($redirect_to)) {
        $redirect_to = 'wp-admin/';
    }
    if ($redirect_to == 'wp-admin/') {
        if (!current_user_can('edit_posts')) {
            $redirect_to .= 'profile.php';
        }
    }
    if (!preg_match('#^(http|\\/)#', $redirect_to)) {
        $wpp = parse_url(get_option('siteurl'));
        $redirect_to = $wpp['path'] . '/' . $redirect_to;
    }
    wp_safe_redirect($redirect_to);
    exit;
}