Ejemplo n.º 1
0
 /**
  * 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 create_new_user($identity_url, &$user_data)
 {
     global $wpdb, $openid;
     // 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
     $user_data['user_login'] = $wpdb->escape(WordPressOpenID_Logic::generate_new_username($identity_url));
     $user_data['user_pass'] = substr(md5(uniqid(microtime())), 0, 7);
     $user_id = wp_insert_user($user_data);
     $openid->log->debug("wp_create_user( {$user_data} )  returned {$user_id} ");
     if ($user_id) {
         // created ok
         $user_data['ID'] = $user_id;
         // XXX this all looks redundant, see WordPressOpenID_Logic::set_current_user
         $openid->log->debug("OpenIDConsumer: Created new user {$user_id} : {$username} and metadata: " . var_export($user_data, true));
         $user = new WP_User($user_id);
         if (!wp_login($user->user_login, $user_data['user_pass'])) {
             $openid->error = 'User was created fine, but wp_login() for the new user failed. ' . 'This is probably a bug.';
             $openid->action = 'error';
             $openid->log->err($openid->error);
             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
         global $userdata;
         $userdata = get_userdata($user_id);
         $store = WordPressOpenID_Logic::getStore();
         $store->insert_identity($user_id, $identity_url);
         $openid->action = 'redirect';
         if (!$user->has_cap('edit_posts')) {
             $redirect_to = '/wp-admin/profile.php';
         }
     } else {
         // failed to create user for some reason.
         $openid->error = 'OpenID authentication successful, but failed to create WordPress user. ' . 'This is probably a bug.';
         $openid->action = 'error';
         $openid->log->error($openid->error);
     }
 }
Ejemplo n.º 2
0
function start_wp_openid()
{
    global $request;
    wp_plugin_include(array('wp-openid'));
    $logic = new WordPressOpenID_Logic(null);
    $logic->activate_plugin();
    if (!WordPressOpenID_Logic::late_bind()) {
        return;
    }
    $redirect_to = '';
    if (!empty($_SESSION['requested_url'])) {
        $redirect_to = $_SESSION['requested_url'];
    }
    $claimed_url = $request->openid_url;
    $consumer = WordPressOpenID_Logic::getConsumer();
    $auth_request = $consumer->begin($claimed_url);
    if (null === $auth_request) {
        trigger_error('OpenID server not found at ' . htmlentities($claimed_url), E_USER_ERROR);
    }
    $return_to = $request->url_for('openid_continue') . '/';
    $store =& WordPressOpenID_Logic::getStore();
    $sreg_request = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname'));
    $auth_request->addExtension($sreg_request);
    $_SESSION['oid_return_to'] = $return_to;
    WordPressOpenID_Logic::doRedirect($auth_request, $request->protected_url, $return_to);
    exit(0);
}
Ejemplo n.º 3
0
 /**
  * Delete user.
  */
 function delete_user($userid)
 {
     openid_init();
     $store = WordPressOpenID_Logic::getStore();
     $store->drop_all_identities_for_user($userid);
 }