Esempio n. 1
0
/**
 * Creates a new integrated user in phpBB to match a given WordPress user
 * @param int $userID the WordPress userID
 * @return int < 1 on failure; >=1 phpbb User ID on success
 */
function wpu_create_phpbb_user($userID)
{
    global $phpbbForum, $config, $db;
    if (!$userID) {
        return -1;
    }
    $wpUsr = get_userdata($userID);
    $fStateChanged = $phpbbForum->foreground();
    $password = wpu_convert_password_format($wpUsr->user_pass, 'to-phpbb');
    // validates and finds a unique username
    if (!($signUpName = wpu_find_next_avail_name($wpUsr->user_login, 'phpbb'))) {
        $phpbbForum->restore_state($fStateChanged);
        return -1;
    }
    $userToAdd = array('username' => $signUpName, 'user_password' => $password, 'user_email' => $wpUsr->user_email, 'user_type' => USER_NORMAL);
    // add to newly registered group if needed
    if ($config['new_member_post_limit']) {
        $userToAdd['user_new'] = 1;
    }
    // Which group by default?
    $sql = 'SELECT group_id
		FROM ' . GROUPS_TABLE . "\n\t\tWHERE group_name = '" . $db->sql_escape('REGISTERED') . "'\n\t\t\tAND group_type = " . GROUP_SPECIAL;
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    $groupID = (int) $row['group_id'];
    $userToAdd['group_id'] = empty($groupID) ? 2 : $groupID;
    $pUserID = 0;
    if ($pUserID = user_add($userToAdd)) {
        wpu_update_int_id($pUserID, $wpUsr->ID);
        update_user_meta($wpUsr->ID, 'phpbb_userid', $pUserID);
    }
    $phpbbForum->restore_state($fStateChanged);
    return $pUserID;
}
Esempio n. 2
0
/**
 * Perform an action requested by the user mapper
 */
function wpu_process_mapaction()
{
    global $phpbbForum, $db, $wpdb, $phpbb_root_path, $phpEx;
    wpu_ajax_header();
    echo '<wpumapaction>';
    $action = isset($_POST['type']) ? (string) $_POST['type'] : '';
    $userID = isset($_POST['userid']) ? (int) $_POST['userid'] : 0;
    $intUserID = isset($_POST['intuserid']) ? (int) $_POST['intuserid'] : 0;
    $package = isset($_POST['package']) ? (string) $_POST['package'] : '';
    if (empty($action) || empty($userID) || empty($package) || $action == 'delboth' && empty($intUserID) || $action == 'break' && empty($intUserID) || $action == 'sync' && empty($intUserID)) {
        wpu_map_action_error('Cannot perform action, required details are missing');
    }
    require_once $phpbb_root_path . 'includes/functions_user.' . $phpEx;
    switch ($action) {
        case 'del':
            if ($package == 'wp') {
                // First break if the user is integrated
                wpu_map_break($userID);
                wp_delete_user($userID, '0');
            } else {
                $fStateChanged = $phpbbForum->foreground();
                user_delete('retain', $userID);
                $phpbbForum->background($fStateChanged);
            }
            echo '<status>OK</status>';
            break;
        case 'delboth':
            $wUserID = $package == 'wp' ? $userID : $intUserID;
            $pUserID = $package == 'wp' ? $intUserID : $userID;
            wp_delete_user($wUserID, '0');
            $fStateChanged = $phpbbForum->foreground();
            user_delete('retain', $pUserID);
            $phpbbForum->background($fStateChanged);
            echo '<status>OK</status>';
            break;
        case 'integrate':
            $wUserID = $package == 'wp' ? $userID : $intUserID;
            $pUserID = $package == 'wp' ? $intUserID : $userID;
            if (!empty($wUserID) && !empty($pUserID)) {
                wpu_update_int_id($pUserID, $wUserID);
                // Sync profiles
                $wpuNewDetails = $phpbbForum->get_userdata('', $pUserID);
                $phpbbForum->background($fStateChanged);
                $wpUsrData = get_userdata($wUserID);
                // Don't modify passwords
                wpu_sync_profiles($wpUsrData, $wpuNewDetails, 'sync', true);
                echo '<status>OK</status>';
            }
            break;
        case 'break':
            $id = $package == 'wp' ? $userID : $intUserID;
            wpu_map_break($id);
            echo '<status>OK</status>';
            break;
        case 'sync':
            $wpUserID = $package == 'wp' ? $userID : $intUserID;
            $pUserID = $package == 'wp' ? $intUserID : $userID;
            $wpUsrData = get_userdata($wpUserID);
            $pUsrData = $phpbbForum->get_userdata('', $pUserID);
            wpu_sync_profiles($wpUsrData, $pUsrData, 'sync', true);
            echo '<status>OK</status>';
            break;
        case 'createin':
            // create user in phpBB
            if ($package == 'phpbb') {
                $phpbbID = wpu_create_phpbb_user($userID);
                if ($phpbbID == 0) {
                    die('<status>FAIL</status><details>' . __('Could not add user to phpBB', 'wp-united') . '</details></wpumapaction>');
                } else {
                    if ($phpbbID == -1) {
                        die('<status>FAIL</status><details>' . __('A suitable username could not be found in phpBB', 'wp-united') . '</details></wpumapaction>');
                    }
                }
                wpu_sync_profiles(get_userdata($userID), $phpbbForum->get_userdata('', $phpbbID), 'wp-update');
            } else {
                // create user in WordPress
                $wpuNewDetails = $phpbbForum->get_userdata('', $userID);
                require_once ABSPATH . WPINC . '/registration.php';
                if (!($userLevel = wpu_get_user_level($userID))) {
                    die('<status>FAIL</status><details>' . __('Cannot create integrated user, as they would have no integration permissions.', 'wp-united') . '</details></wpumapaction>');
                }
                $newUserID = wpu_create_wp_user($wpuNewDetails['username'], $wpuNewDetails['user_password'], $wpuNewDetails);
                if ($newUserID) {
                    if ($wpUser = get_userdata($newUserID)) {
                        wpu_update_int_id($userID, $wpUser->ID);
                        wpu_sync_profiles($wpUser, $wpuNewDetails, 'phpbb-update');
                        wpu_set_role($wpUser->ID, $userLevel);
                    }
                } else {
                    die('<status>FAIL</status><details>' . __('Could not add user to WordPress', 'wp-united') . '</details></wpumapaction>');
                }
            }
            echo '<status>OK</status>';
            break;
    }
    echo '<nonce>' . wp_create_nonce('wp-united-mapaction') . '</nonce>';
    echo '</wpumapaction>';
    die;
}
Esempio n. 3
0
 /**
  * checks a login with username and password. If it failed, but the user they tried to log in as
  * has an integrated phpBB user with a correct username and password, allow the login to proceed
  * @param mixed $user WP_User|WP_Error|null a user object if the user has already successfully authenticated
  * @param string $username attempted username
  * @param string $password attempted password
  * @return an authenticated WP_User object, or WP_Error or void on error
  */
 public function authenticate($user, $username, $password)
 {
     global $phpbbForum;
     if (is_a($user, 'WP_User')) {
         return $user;
     }
     if (!$this->is_working()) {
         return $user;
     }
     if (!$this->get_setting('integrateLogin')) {
         return;
     }
     // phpBB does some processing of inbound strings so password could be modified
     set_var($phpbbPass, stripslashes($password), 'string', true);
     if (!$phpbbForum->login($username, $phpbbPass)) {
         return $user;
         // return an error
     }
     if ($integratedID = wpu_get_integration_id()) {
         return get_userdata($integratedID);
     }
     // If we've got here, we have a valid phpBB user that isn't integrated in WordPress
     // Should this phpBB user get an account? If not, we can just stay unintegrated
     if (!$this->get_setting('integcreatewp') || !($userLevel = wpu_get_user_level())) {
         return $user;
     }
     $signUpName = $phpbbForum->get_username();
     $newUserID = wpu_create_wp_user($signUpName, $phpbbForum->get_userdata('user_password'), $phpbbForum->get_userdata('user_email'));
     if ($newUserID) {
         if (!is_a($newUserID, 'WP_Error')) {
             wpu_set_role($newUserID, $userLevel);
             wpu_update_int_id($phpbbForum->get_userdata('user_id'), $newUserID);
             wpu_sync_profiles(get_userdata($newUserID), $phpbbForum->get_userdata(), 'sync');
             return get_userdata($newUserID);
         }
     }
     //just return whatever error was passed in
     return $user;
 }