コード例 #1
0
ファイル: login.php プロジェクト: gerasiov/wordpress-openid
/**
 * 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;
}
コード例 #2
0
ファイル: login.php プロジェクト: BackupTheBerlios/oos-svn
/**
 * 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;
}
コード例 #3
0
ファイル: comments.php プロジェクト: alx/alexgirard.com-blog
/**
 * Action method for completing the 'comment' action.  This action is used when leaving a comment.
 *
 * @param string $identity_url verified OpenID URL
 */
function openid_finish_comment($identity_url)
{
    if ($_REQUEST['action'] != 'comment') {
        return;
    }
    if (empty($identity_url)) {
        openid_repost_comment_anonymously($_SESSION['openid_comment_post']);
    }
    openid_set_current_user($identity_url);
    if (is_user_logged_in()) {
        // simulate an authenticated comment submission
        $_SESSION['openid_comment_post']['author'] = null;
        $_SESSION['openid_comment_post']['email'] = null;
        $_SESSION['openid_comment_post']['url'] = null;
    } else {
        // try to get user data from the verified OpenID
        $user_data =& openid_get_user_data($identity_url);
        if (!empty($user_data['display_name'])) {
            $_SESSION['openid_comment_post']['author'] = $user_data['display_name'];
        }
        if (!empty($user_data['user_email'])) {
            $_SESSION['openid_comment_post']['email'] = $user_data['user_email'];
        }
        $_SESSION['openid_comment_post']['url'] = $identity_url;
    }
    // record that we're about to post an OpenID authenticated comment.
    // We can't actually record it in the database until after the repost below.
    $_SESSION['openid_posted_comment'] = true;
    $comment_page = defined('OPENID_COMMENTS_POST_PAGE') ? OPENID_COMMENTS_POST_PAGE : 'wp-comments-post.php';
    openid_repost(site_url("/{$comment_page}"), array_filter($_SESSION['openid_comment_post']));
}
コード例 #4
0
ファイル: wp-login.php プロジェクト: alx/pressid
/**
 * 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;
}