コード例 #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
ファイル: common.php プロジェクト: alx/pressid
/**
 * Create a new WordPress user with the specified identity URL and user data.
 *
 * @param string $identity_url OpenID to associate with the newly
 * created account
 * @param array $user_data array of user data
 */
function openid_create_new_user($identity_url, &$user_data)
{
    global $wpdb;
    // Identity URL is new, so create a user
    @(include_once ABSPATH . 'wp-admin/upgrade-functions.php');
    // 2.1
    @(include_once ABSPATH . WPINC . '/registration-functions.php');
    // 2.0.4
    // use email address for username if URL is from emailtoid.net
    $username = $identity_url;
    if (null != $_SESSION['openid_login_email'] and strpos($username, 'http://emailtoid.net/') == 0) {
        if ($user_data['user_email'] == NULL) {
            $user_data['user_email'] = $_SESSION['openid_login_email'];
        }
        $username = $_SESSION['openid_login_email'];
        unset($_SESSION['openid_login_email']);
    }
    $user_data['user_login'] = $wpdb->escape(openid_generate_new_username($username));
    $user_data['user_pass'] = substr(md5(uniqid(microtime())), 0, 7);
    $user_id = wp_insert_user($user_data);
    if ($user_id) {
        // created ok
        $user_data['ID'] = $user_id;
        // XXX this all looks redundant, see openid_set_current_user
        $user = new WP_User($user_id);
        if (!wp_login($user->user_login, $user_data['user_pass'])) {
            openid_message(__('User was created fine, but wp_login() for the new user failed. This is probably a bug.', 'openid'));
            openid_action('error');
            openid_error(openid_message());
            return;
        }
        // notify of user creation
        wp_new_user_notification($user->user_login);
        wp_clearcookie();
        wp_setcookie($user->user_login, md5($user->user_pass), true, '', '', true);
        // Bind the provided identity to the just-created user
        openid_add_user_identity($user_id, $identity_url);
        openid_status('redirect');
        if (!$user->has_cap('edit_posts')) {
            $redirect_to = '/wp-admin/profile.php';
        }
    } else {
        // failed to create user for some reason.
        openid_message(__('OpenID authentication successful, but failed to create WordPress user. This is probably a bug.', 'openid'));
        openid_status('error');
        openid_error(openid_message());
    }
}
コード例 #3
0
/**
 * Start the OpenID authentication process.
 *
 * @param string $claimed_url claimed OpenID URL
 * @param string $action OpenID action being performed
 * @param string $finish_url stored in user session for later redirect
 * @uses apply_filters() Calls 'openid_auth_request_extensions' to gather extensions to be attached to auth request
 */
function openid_start_login($claimed_url, $action, $finish_url = null)
{
    if (empty($claimed_url)) {
        return;
    }
    // do nothing.
    $auth_request = openid_begin_consumer($claimed_url);
    if (null === $auth_request) {
        openid_status('error');
        openid_message(sprintf(__('Could not discover an OpenID identity server endpoint at the url: %s', 'openid'), htmlentities($claimed_url)));
        return;
    }
    @session_start();
    $_SESSION['openid_action'] = $action;
    $_SESSION['openid_finish_url'] = $finish_url;
    $extensions = apply_filters('openid_auth_request_extensions', array(), $auth_request);
    foreach ($extensions as $e) {
        if (is_a($e, 'Auth_OpenID_Extension')) {
            $auth_request->addExtension($e);
        }
    }
    $return_to = openid_service_url('consumer', 'login_post');
    $return_to = apply_filters('openid_return_to', $return_to);
    $trust_root = openid_trust_root($return_to);
    openid_redirect($auth_request, $trust_root, $return_to);
    exit(0);
}
コード例 #4
0
function openid_profile_update($user_id)
{
    if (empty($_POST['openid_delegate'])) {
        delete_usermeta($user_id, 'openid_delegate');
    } else {
        $old_delegate = get_usermeta($user_id, 'openid_delegate');
        $delegate = Auth_OpenID::normalizeUrl($_POST['openid_delegate']);
        if (openid_server_update_delegation_info($user_id, $delegate)) {
            openid_message(sprintf(__('Gathered OpenID information for delegate URL %s', 'openid'), '<strong>' . $delegate . '</strong>'));
            openid_status('success');
        } else {
            openid_message(sprintf(__('Unable to find any OpenID information for delegate URL %s', 'openid'), '<strong>' . $delegate . '</strong>'));
            openid_status('error');
        }
    }
}
コード例 #5
0
/**
 * Action method for completing the 'verify' action.  This action is used adding an identity URL to a
 * WordPress user through the admin interface.
 *
 * @param string $identity_url verified OpenID URL
 */
function openid_finish_verify($identity_url, $action)
{
    if ($action != 'verify') {
        return;
    }
    $message;
    $user = wp_get_current_user();
    if (empty($identity_url)) {
        $message = openid_message();
        if (empty($message)) {
            $message = 1;
        }
    } else {
        if (!openid_add_identity($user->ID, $identity_url)) {
            $message = 2;
        } else {
            $message = 3;
            // ensure that profile URL is a verified OpenID
            set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
            require_once 'Auth/OpenID.php';
            require_once ABSPATH . 'wp-admin/includes/admin.php';
            if (!openid_ensure_url_match($user)) {
                wp_update_user(array('ID' => $user->ID, 'user_url' => $identity_url));
                $update_url = 1;
            }
        }
    }
    $finish_url = $_SESSION['openid_finish_url'];
    $finish_url = add_query_arg('status', openid_status(), $finish_url);
    $finish_url = add_query_arg('message', $message, $finish_url);
    if (isset($update_url) && $update_url) {
        $finish_url = add_query_arg('update_url', $update_url, $finish_url);
    }
    wp_safe_redirect($finish_url);
    exit;
}
コード例 #6
0
ファイル: common.php プロジェクト: BackupTheBerlios/oos-svn
/**
 * Create a new WordPress user with the specified identity URL and user data.
 *
 * @param string $identity_url OpenID to associate with the newly
 * created account
 * @param array $user_data array of user data
 */
function openid_create_new_user($identity_url, &$user_data) {
	global $wpdb;

	// Identity URL is new, so create a user
	@include_once( ABSPATH . 'wp-admin/upgrade-functions.php');	// 2.1
	@include_once( ABSPATH . WPINC . '/registration-functions.php'); // 2.0.4

	// otherwise, try to use preferred username
	if ( empty($username) && array_key_exists('nickname', $user_data) ) {
		$username = openid_generate_new_username($user_data['nickname'], false);
	}

	// finally, build username from OpenID URL
	if (empty($username)) {
		$username = openid_generate_new_username($identity_url);
	}

	$user_data['user_login'] = $username;
	$user_data['user_pass'] = substr( md5( uniqid( microtime() ) ), 0, 7);
	$user_id = wp_insert_user( $user_data );

	if( $user_id ) { // created ok

		$user_data['ID'] = $user_id;
		// XXX this all looks redundant, see openid_set_current_user

		$user = new WP_User( $user_id );

		if( ! wp_login( $user->user_login, $user_data['user_pass'] ) ) {
			openid_message(__('User was created fine, but wp_login() for the new user failed. This is probably a bug.', 'openid'));
			openid_status('error');
			openid_error(openid_message());
			return;
		}

		// notify of user creation
		wp_new_user_notification( $user->user_login );

		wp_clearcookie();
		wp_setcookie( $user->user_login, md5($user->user_pass), true, '', '', true );

		// Bind the provided identity to the just-created user
		openid_add_user_identity($user_id, $identity_url);

		openid_status('redirect');

		if ( !$user->has_cap('edit_posts') ) $redirect_to = '/wp-admin/profile.php';

	} else {
		// failed to create user for some reason.
		openid_message(__('OpenID authentication successful, but failed to create WordPress user. This is probably a bug.', 'openid'));
		openid_status('error');
		openid_error(openid_message());
	}

}
コード例 #7
0
ファイル: common.php プロジェクト: gerasiov/wordpress-openid
/**
 * Create a new WordPress user with the specified identity URL and user data.
 *
 * @param string $identity_url OpenID to associate with the newly
 * created account
 * @param array $user_data array of user data
 * @uses do_action() Calls 'openid_consumer_new_user_custom_data' hook action after creating user
 */
function openid_create_new_user($identity_url, &$user_data)
{
    global $wpdb;
    // Identity URL is new, so create a user
    @(include_once ABSPATH . 'wp-admin/upgrade-functions.php');
    // 2.1
    @(include_once ABSPATH . WPINC . '/registration-functions.php');
    // 2.0.4
    // otherwise, try to use preferred username
    if (empty($username) && array_key_exists('nickname', $user_data)) {
        $username = openid_generate_new_username($user_data['nickname'], false);
    }
    // try using email address before resorting to URL
    if (empty($username) && array_key_exists('user_email', $user_data)) {
        $username = openid_generate_new_username($user_data['user_email'], false);
    }
    // finally, build username from OpenID URL
    if (empty($username)) {
        $username = openid_generate_new_username($identity_url);
    }
    $user_data['user_login'] = $username;
    $user_data['display_name'] = $username;
    $user_data['user_pass'] = substr(md5(uniqid(microtime())), 0, 7);
    $user_id = wp_insert_user($user_data);
    if ($user_id instanceof WP_Error) {
        openid_message($user_id->get_error_message());
        openid_status('error');
        return;
    } else {
        if (is_integer($user_id)) {
            // created ok
            $user_data['ID'] = $user_id;
            // XXX this all looks redundant, see openid_set_current_user
            $user = new WP_User($user_id);
            $credentials = array('user_login' => $user->user_login, 'user_password' => $user_data['user_pass'], 'remember' => true);
            if (!wp_signon($credentials)) {
                openid_message(__('User was created fine, but wp_signon() for the new user failed. This is probably a bug.', 'openid'));
                openid_status('error');
                openid_error(openid_message());
                return;
            }
            // notify of user creation
            wp_new_user_notification($user_id);
            wp_clear_auth_cookie();
            wp_set_auth_cookie($user_id, true);
            // Bind the provided identity to the just-created user
            openid_add_user_identity($user_id, $identity_url);
            openid_status('redirect');
            do_action('openid_consumer_new_user_custom_data', $user_id, $user_data);
            if (!$user->has_cap('edit_posts')) {
                $redirect_to = '/wp-admin/profile.php';
            }
        } else {
            // failed to create user for some reason.
            openid_message(__('OpenID authentication successful, but failed to create WordPress user. This is probably a bug.', 'openid'));
            openid_status('error');
            openid_error(openid_message());
        }
    }
}