Example #1
0
function open_action($os)
{
    if (!isset($_SESSION['open_id'])) {
        $newuser = $os->open_new_user();
    }
    if (!$_SESSION['access_token'] || !$_SESSION['open_id'] || strlen($_SESSION['open_id']) < 6 || strlen($_SESSION['access_token']) < 6 || !OPEN_TYPE) {
        return;
    }
    if (is_user_logged_in()) {
        //bind
        $wpuid = get_current_user_id();
        if (open_isbind(OPEN_TYPE, $_SESSION['open_id'])) {
            open_close($GLOBALS['open_str']['err_other_openid']);
        } else {
            $open_id = get_user_meta($wpuid, 'open_id', true);
            if ($open_id) {
                open_close($GLOBALS['open_str']['err_other_user']);
            }
        }
    } else {
        //login
        if (!isset($newuser)) {
            $newuser = $os->open_new_user();
        }
        //refresh avatar in case
        $wpuid = open_isbind(OPEN_TYPE, $_SESSION['open_id']);
        if (!$wpuid) {
            $wpuid = username_exists(strtoupper(OPEN_TYPE) . $_SESSION['open_id']);
            if (!$wpuid) {
                $userdata = array('user_pass' => wp_generate_password(), 'user_login' => strtoupper(OPEN_TYPE) . $_SESSION['open_id'], 'show_admin_bar_front' => 'false');
                $userdata = array_merge($userdata, $newuser);
                if (email_exists($userdata['user_email'])) {
                    open_close($GLOBALS['open_str']['err_other_email']);
                }
                //Google,Live
                if (!function_exists('wp_insert_user')) {
                    include_once ABSPATH . WPINC . '/registration.php';
                }
                $wpuid = wp_insert_user($userdata);
                wp_update_user(array('ID' => $wpuid, 'role' => 'subscriber'));
                //too open to have an option here
            }
        }
    }
    if ($wpuid) {
        update_user_meta($wpuid, 'open_type', OPEN_TYPE);
        if (isset($_SESSION['open_img'])) {
            update_user_meta($wpuid, 'open_img', $_SESSION['open_img']);
        }
        update_user_meta($wpuid, 'open_id', $_SESSION['open_id']);
        update_user_meta($wpuid, 'open_access_token', $_SESSION["access_token"]);
        wp_set_auth_cookie($wpuid, true, false);
        wp_set_current_user($wpuid);
    }
    unset($_SESSION['open_id']);
    unset($_SESSION["access_token"]);
    if (isset($_SESSION['open_img'])) {
        unset($_SESSION['open_img']);
    }
    $back = isset($_SESSION['back']) ? $_SESSION['back'] : home_url();
    if (isset($_SESSION['back'])) {
        unset($_SESSION['back']);
    }
    header('Location:' . $back);
    exit;
}
Example #2
0
function open_action($os)
{
    if (!isset($_SESSION['open_id'])) {
        $newuser = $os->open_new_user();
    }
    if (!$_SESSION['open_id'] || strlen($_SESSION['open_id']) < 6 || !$_SESSION['access_token'] || strlen($_SESSION['access_token']) < 6 || !OPEN_TYPE) {
        return;
    }
    if (is_user_logged_in()) {
        //bind
        $wpuid = get_current_user_id();
        if (open_isbind(OPEN_TYPE, $_SESSION['open_id'])) {
            open_close(__('This account has been bound with other user.', 'open-social'));
        }
    } else {
        //login
        if (!isset($newuser)) {
            $newuser = $os->open_new_user();
        }
        //refresh avatar in case
        $wpuid = open_isbind(OPEN_TYPE, $_SESSION['open_id']);
        if (!$wpuid) {
            $wpuid = username_exists(strtoupper(OPEN_TYPE) . $_SESSION['open_id']);
            if (!$wpuid) {
                if (email_exists($newuser['user_email'])) {
                    open_close(sprintf(__('This email [%s] has been registered by other user.', 'open-social'), $newuser['user_email']));
                }
                //Google,Live
                $userdata = array('user_pass' => wp_generate_password(), 'user_login' => strtoupper(OPEN_TYPE) . $_SESSION['open_id']);
                if (osop('extend_hide_user_bar', 1)) {
                    $userdata['show_admin_bar_front'] = 'false';
                }
                $userdata = array_merge($userdata, $newuser);
                if (!function_exists('wp_insert_user')) {
                    include_once ABSPATH . WPINC . '/registration.php';
                }
                $wpuid = wp_insert_user($userdata);
                if (osop('extend_user_role', 1)) {
                    wp_update_user(array('ID' => $wpuid, 'role' => 'subscriber'));
                }
            }
        }
    }
    if ($wpuid) {
        $open_type_list = get_user_meta($wpuid, 'open_type', true);
        if ($open_type_list) {
            $open_type_list = trim($open_type_list, ',') . ',';
        }
        if (stripos($open_type_list, OPEN_TYPE) === false) {
            update_user_meta($wpuid, 'open_type', $open_type_list . OPEN_TYPE . ',');
        }
        update_user_meta($wpuid, 'open_type_' . OPEN_TYPE, $_SESSION['open_id']);
        if (isset($_SESSION['open_img'])) {
            update_user_meta($wpuid, 'open_img', $_SESSION['open_img']);
            unset($_SESSION['open_img']);
        }
        update_user_meta($wpuid, 'open_access_token', $_SESSION["access_token"]);
        wp_set_auth_cookie($wpuid, true, false);
        wp_set_current_user($wpuid);
    }
    unset($_SESSION['open_id']);
    unset($_SESSION["access_token"]);
    $back = isset($_SESSION['back']) ? $_SESSION['back'] : home_url();
    if (isset($_SESSION['back'])) {
        unset($_SESSION['back']);
    }
    header('Location:' . $back);
    exit;
}