Ejemplo n.º 1
0
function wp_connect_login($userinfo, $tmail, $uid = '', $reg = false)
{
    global $wpdb, $wptm_connect;
    $redirect_to = !empty($_SESSION['wp_url_back']) ? $_SESSION['wp_url_back'] : get_bloginfo('url');
    if (!$uid && !$reg) {
        // 新用户
        wp_connect_set_cookie("wp_connect_cookie_user", array($userinfo, $tmail, $redirect_to), BJTIMESTAMP + 600);
        $new_user = true;
        if ($userinfo[0] == 'qqtid' && empty($wptm_connect['chinese_username'])) {
            // QQ帐号登录,没有勾选支持中文用户名时。
            $wptm_connect['reg'] = true;
        }
    }
    if ($new_user && $wptm_connect['reg']) {
        // 强制填写注册信息
        return wp_connect_reg();
    }
    $tid = $userinfo[0];
    $user_name = $userinfo[1];
    $user_screenname = $userinfo[2];
    $user_head = $userinfo[3];
    $user_siteurl = $userinfo[4];
    $user_uid = $userinfo[5];
    $oauth_token = $userinfo[6];
    if ($user_name) {
        if ($new_user && in_array($user_name, explode(',', $wptm_connect['disable_username']))) {
            return wp_connect_reg();
        }
    } else {
        wp_die("获取用户授权信息失败,请重新<a href=\"" . site_url('wp-login.php', 'login') . "\">登录</a> 或者 清除浏览器缓存再试! [ <a href='{$redirect_to}'>返回</a> ]");
    }
    if ($uid) {
        $wpuid = $uid;
    } elseif ($new_user) {
        $wpuid = username_exists($user_name);
        if ($wpuid) {
            // 新注册,但是数据库存在相同的用户名
            return wp_connect_reg();
        }
    }
    if (!$wpuid) {
        if (!function_exists('wp_insert_user')) {
            include_once ABSPATH . WPINC . '/registration.php';
        }
        $userdata = array('user_login' => $user_name, 'user_pass' => ifab($userinfo[8], wp_generate_password()), 'user_email' => $tmail, 'user_url' => $user_siteurl, 'user_nicename' => $user_name, 'nickname' => $user_screenname, 'display_name' => $user_screenname);
        $wpuid = wp_insert_user($userdata);
        if (!is_numeric($wpuid)) {
            $errors = $wpuid->errors;
            if ($errors['existing_user_email']) {
                wp_die("该电子邮件地址 {$tmail} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]");
            } elseif ($errors['existing_user_login']) {
                wp_die("该用户名 {$user_name} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]");
            }
        }
    }
    if ($wpuid) {
        $weibo = get_weibo($tid);
        $t = $weibo[0];
        $id = $weibo[1] . 'id';
        if ($tid == $id) {
            // UID
            update_usermeta($wpuid, $tid, $user_uid);
        } else {
            if ($user_head) {
                // 头像
                update_usermeta($wpuid, $tid, $user_head);
            }
            update_usermeta($wpuid, $id, $user_uid);
        }
        update_usermeta($wpuid, 'last_login', $tid);
        if ($oauth_token) {
            // 授权信息
            if ($oauth_token['access_token']) {
                $token = array($oauth_token['access_token'], $oauth_token['expires_in'], $user_uid, $user_name);
            } else {
                $token = array($oauth_token['oauth_token'], $oauth_token['oauth_token_secret'], $user_uid, $user_name);
            }
            update_usermeta($wpuid, 'login_' . $t, $token);
            if (!$uid && $wptm_connect['sync']) {
                // 用户首次登录的时候也绑定同步帐号
                update_usermeta($wpuid, 'wptm_' . $t, $oauth_token);
            }
            if (in_array($tid, array('qtid', 'stid', 'ntid', 'shtid', 'ttid'))) {
                // @微博帐号
                $nickname = get_user_meta($wpuid, 'login_name', true);
                $nickname[$t] = $t == 'qq' || $t == 'twitter' ? $user_uid : $user_screenname;
                update_usermeta($wpuid, 'login_name', $nickname);
            }
        }
        wp_set_auth_cookie($wpuid, true, false);
        wp_set_current_user($wpuid);
    }
    $_SESSION['wp_url_login'] = '';
    wp_connect_clear_cookie("wp_connect_cookie_user");
    return $wpuid;
}
Ejemplo n.º 2
0
<?php

include "../../../wp-config.php";
do_action('connect_init');
if (isset($_GET['go'])) {
    $name = strtolower($_GET['go']);
    if (in_array($name, array('qzone', 'sina', 'tencent', 'renren', 'taobao', 'douban', 'baidu', 'kaixin001', 'sohu', 'netease', 'tianya', 'windowslive', 'alipayquick', 'google', 'yahoo', 'netease163', 'twitter', 'facebook', 'tianyi', 'guard360'))) {
        $wptm_basic = get_option('wptm_basic');
        if (is_user_logged_in()) {
            // 同步绑定
            wp_connect_set_cookie("wp_connect_cookie_bind", "sync", BJTIMESTAMP + 600);
        }
        if (!empty($_SERVER['HTTP_REFERER'])) {
            if (strpos($_SERVER['HTTP_REFERER'], "redirect_to=") !== false) {
                $parse_str = parse_url_detail($_SERVER['HTTP_REFERER']);
                $redirect_uri = $parse_str['redirect_to'];
            } else {
                $redirect_uri = $_SERVER['HTTP_REFERER'];
            }
            $redirect_uri = "&redirect_uri=" . urlencode($redirect_uri);
        }
        $open_url = "http://open.denglu.cc/transfer/" . $name . "?appid=" . $wptm_basic['appid'] . $redirect_uri;
        header('Location:' . $open_url);
    }
} elseif (is_user_logged_in() && !empty($_SERVER['HTTP_REFERER']) && isset($_GET['user_id'])) {
    $user_id = $_GET['user_id'];
    if (!$user_ID) {
        $user_ID = get_current_user_id();
    }
    if ($user_id && ($user_ID == $user_id || current_user_can('manage_options'))) {
        if (isset($_GET['bind'])) {
Ejemplo n.º 3
0
function wp_connect_login($userinfo, $tmail, $uid = '', $reg = false)
{
    global $wpdb, $wptm_connect;
    $redirect_to = !empty($_GET['redirect_url']) ? $_GET['redirect_url'] : get_bloginfo('url');
    if (!$uid && !$reg) {
        // 新用户
        $new_user = true;
        wp_connect_set_cookie("wp_connect_cookie_user", array($userinfo, $tmail, $redirect_to), BJTIMESTAMP + 600);
    }
    if ($new_user && $wptm_connect['reg']) {
        // 强制填写注册信息
        return wp_connect_reg();
    }
    $tid = $userinfo[0];
    $user_name = $userinfo[1];
    $user_screenname = $userinfo[2];
    $user_head = $userinfo[3];
    $user_siteurl = $userinfo[4];
    $user_uid = $userinfo[5];
    $mediaUserID = $userinfo[6];
    //2.0
    if ($user_name) {
        if ($new_user && in_array($user_name, explode(',', $wptm_connect['disable_username']))) {
            return wp_connect_reg();
        }
    } else {
        wp_die("获取用户授权信息失败,请重新<a href=\"" . site_url('wp-login.php', 'login') . "\">登录</a> 或者 清除浏览器缓存再试! [ <a href='{$redirect_to}'>返回</a> ]");
    }
    if ($uid) {
        $wpuid = $uid;
    } elseif ($new_user) {
        $wpuid = username_exists($user_name);
        if ($wpuid) {
            // 新注册,但是数据库存在相同的用户名
            return wp_connect_reg();
        }
    }
    if (!$wpuid) {
        if (!function_exists('wp_insert_user')) {
            include_once ABSPATH . WPINC . '/registration.php';
        }
        $userdata = array('user_login' => $user_name, 'user_pass' => ifab($userinfo[8], wp_generate_password()), 'user_email' => $tmail, 'user_url' => $user_siteurl, 'user_nicename' => $user_name, 'nickname' => $user_screenname, 'display_name' => $user_screenname);
        $wpuid = wp_insert_user($userdata);
        if (!is_numeric($wpuid)) {
            $errors = $wpuid->errors;
            if ($errors['existing_user_email']) {
                wp_die("该电子邮件地址 {$tmail} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]");
            } elseif ($errors['existing_user_login']) {
                wp_die("该用户名 {$user_name} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]");
            }
        }
    }
    if ($wpuid) {
        $weibo = get_weibo($tid);
        $t = $weibo[0];
        $id = $weibo[1] . 'id';
        $mid = str_replace('tid', 'mid', $tid);
        update_usermeta($wpuid, $mid, $mediaUserID);
        if ($tid == $id) {
            update_usermeta($wpuid, $tid, $user_uid);
        } elseif ($user_head) {
            update_usermeta($wpuid, $tid, $user_head);
        }
        if ($weibo[3] || $tid == 'qqtid') {
            // sina,tqq,sohu,netease,renren,kaixin,douban,qq,tianya
            update_usermeta($wpuid, $id, $user_uid);
        }
        if ($tid == 'guard360tid') {
            // 360
            update_usermeta($wpuid, $id, $user_screenname);
        }
        update_usermeta($wpuid, 'last_login', $tid);
        if (in_array($tid, array('qtid', 'stid', 'ntid', 'shtid', 'ttid'))) {
            // @微博帐号
            $nickname = get_user_meta($wpuid, 'login_name', true);
            $nickname[$t] = $tid == 'qtid' || $tid == 'ttid' ? $user_uid : $user_screenname;
            update_usermeta($wpuid, 'login_name', $nickname);
        }
        wp_set_auth_cookie($wpuid, true, false);
        wp_set_current_user($wpuid);
    }
    wp_connect_clear_cookie("wp_connect_cookie_user");
    return $wpuid;
}