Example #1
0
 function binding_callback_action()
 {
     $oauth = new Services_Weibo_WeiboOAuth(get_setting('sina_akey'), get_setting('sina_skey'));
     if ($_GET['uid'] and $this->user_info['permission']['is_administortar']) {
         $user_id = intval($_GET['uid']);
         $user_info = $this->model('account')->get_user_info_by_uid($user_id);
         if (empty($user_info)) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('本地用户不存在,无法绑定')));
         }
         $sina_token = $oauth->getAccessToken('code', array('code' => $_GET['code'], 'redirect_uri' => get_js_url('/account/sina/binding_callback/uid-' . $user_id)));
     } else {
         $user_id = $this->user_id;
         AWS_APP::session()->sina_token = $oauth->getAccessToken('code', array('code' => $_GET['code'], 'redirect_uri' => get_js_url('/account/sina/binding_callback/')));
         $sina_token = AWS_APP::session()->sina_token;
         $redirect = get_js_url('/account/setting/openid/');
     }
     $client = new Services_Weibo_WeiboClient(get_setting('sina_akey'), get_setting('sina_skey'), $sina_token['access_token']);
     $uid_get = $client->get_uid();
     $sina_profile = $client->show_user_by_id($uid_get['uid']);
     if ($sina_profile['error']) {
         H::redirect_msg(AWS_APP::lang()->_t('与微博通信出错, 错误代码: %s', $sina_profile['error']), "/account/setting/openid/");
     }
     if (!$this->model('integral')->fetch_log($user_id, 'BIND_OPENID')) {
         $this->model('integral')->process($user_id, 'BIND_OPENID', round(get_setting('integral_system_config_profile') * 0.2), '绑定 OPEN ID');
     }
     //$this->model('openid_weibo')->bind_account($sina_profile, get_js_url('/account/setting/openid/'), $user_id, $last_key['oauth_token'], $last_key['oauth_token_secret'], $sina_token);
     $this->model('openid_weibo')->bind_account($sina_profile, $redirect, $user_id, $sina_token);
 }
Example #2
0
 public function create_comment($access_token, $id, $comment)
 {
     $client = new Services_Weibo_WeiboClient(get_setting('sina_akey'), get_setting('sina_skey'), $access_token);
     return $client->send_comment($id, cjk_substr($comment, 0, 140, 'UTF-8', '...'));
 }
Example #3
0
 public function sina_callback_action()
 {
     if (get_setting('sina_weibo_enabled') != 'Y') {
         HTTP::redirect('/account/login/');
     }
     if ($this->is_post() and AWS_APP::session()->sina_profile and !AWS_APP::session()->sina_token['error']) {
         if (get_setting('register_type') == 'close') {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('本站目前关闭注册')));
         } else {
             if (get_setting('register_type') == 'invite') {
                 H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('本站只能通过邀请注册')));
             } else {
                 if (get_setting('register_type') == 'weixin') {
                     H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('本站只能通过微信注册')));
                 }
             }
         }
         if (trim($_POST['user_name']) == '') {
             H::ajax_json_output(AWS_APP::RSM(array('input' => 'user_name'), -1, AWS_APP::lang()->_t('请输入真实姓名')));
         } else {
             if ($this->model('account')->check_username($_POST['user_name'])) {
                 H::ajax_json_output(AWS_APP::RSM(array('input' => 'user_name'), -1, AWS_APP::lang()->_t('真实姓名已经存在')));
             } else {
                 if ($check_rs = $this->model('account')->check_username_char($_POST['user_name'])) {
                     H::ajax_json_output(AWS_APP::RSM(array('input' => 'user_name'), -1, $check_rs));
                 } else {
                     if ($this->model('account')->check_username_sensitive_words($_POST['user_name'])) {
                         H::ajax_json_output(AWS_APP::RSM(array('input' => 'user_name'), -1, AWS_APP::lang()->_t('真实姓名中包含敏感词或系统保留字')));
                     }
                 }
             }
         }
         if ($this->model('account')->check_email($_POST['email'])) {
             H::ajax_json_output(AWS_APP::RSM(array('input' => 'email'), -1, AWS_APP::lang()->_t('E-Mail 已经被使用, 或格式不正确')));
         }
         if (strlen($_POST['password']) < 6 or strlen($_POST['password']) > 16) {
             H::ajax_json_output(AWS_APP::RSM(array('input' => 'userPassword'), -1, AWS_APP::lang()->_t('密码长度不符合规则')));
         }
         if (!$_POST['agreement_chk']) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('你必需同意用户协议才能继续')));
         }
         if (get_setting('ucenter_enabled') == 'Y') {
             $result = $this->model('ucenter')->register($_POST['user_name'], $_POST['password'], $_POST['email'], true);
             if (is_array($result)) {
                 $uid = $result['user_info']['uid'];
             } else {
                 H::ajax_json_output(AWS_APP::RSM(null, -1, $result));
             }
         } else {
             $uid = $this->model('account')->user_register($_POST['user_name'], $_POST['password'], $_POST['email']);
             if (get_setting('register_valid_type') == 'email') {
                 $this->model('active')->new_valid_email($uid);
             }
             if (get_setting('register_valid_type') != 'approval') {
                 $this->model('active')->active_user_by_uid($uid);
             }
         }
         if ($uid) {
             $this->model('openid_weibo')->bind_account(AWS_APP::session()->sina_profile, null, $uid, AWS_APP::session()->sina_token, true);
             if (AWS_APP::session()->sina_profile['profile_image_url']) {
                 $this->model('account')->associate_remote_avatar($uid, str_replace('/50/', '/180/', AWS_APP::session()->sina_profile['profile_image_url']));
             }
             H::ajax_json_output(AWS_APP::RSM(null, 1, null));
         } else {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('与微博通信出错 (Register), 请重新登录')));
         }
     } else {
         if ($_GET['code'] and (!AWS_APP::session()->sina_token or AWS_APP::session()->sina_token['error'])) {
             $oauth = new Services_Weibo_WeiboOAuth(get_setting('sina_akey'), get_setting('sina_skey'));
             AWS_APP::session()->sina_token = $oauth->getAccessToken('code', array('code' => $_GET['code'], 'redirect_uri' => get_js_url('/account/openid/sina_callback/')));
             $client = new Services_Weibo_WeiboClient(get_setting('sina_akey'), get_setting('sina_skey'), AWS_APP::session()->sina_token['access_token']);
             $uid_get = $client->get_uid();
             $sina_profile = $client->show_user_by_id($uid_get['uid']);
             if ($sina_profile['error']) {
                 H::redirect_msg(AWS_APP::lang()->_t('与微博通信出错, 错误代码: %s', $sina_profile['error']), '/account/login/');
             }
             AWS_APP::session()->sina_profile = $sina_profile;
         }
         if (!AWS_APP::session()->sina_profile) {
             H::redirect_msg(AWS_APP::lang()->_t('与微博通信出错, 请重新登录'), '/account/login/');
         }
         if ($sina_user = $this->model('openid_weibo')->get_users_sina_by_id(AWS_APP::session()->sina_profile['id'])) {
             $user_info = $this->model('account')->get_user_info_by_uid($sina_user['uid']);
             HTTP::set_cookie('_user_login', get_login_cookie_hash($user_info['user_name'], $user_info['password'], $user_info['salt'], $user_info['uid'], false));
             $this->model('openid_weibo')->refresh_access_token($sina_user['id'], AWS_APP::session()->sina_token);
             unset(AWS_APP::session()->sina_profile);
             unset(AWS_APP::session()->sina_token);
             if (get_setting('ucenter_enabled') == 'Y') {
                 HTTP::redirect('/account/sync_login/');
             } else {
                 HTTP::redirect('/');
             }
         } else {
             if ($this->user_id) {
                 $this->model('openid_weibo')->bind_account(AWS_APP::session()->sina_profile, '/', $this->user_id, AWS_APP::session()->sina_token);
             } else {
                 if (get_setting('register_type') == 'close') {
                     H::redirect_msg(AWS_APP::lang()->_t('本站目前关闭注册'));
                 } else {
                     if (get_setting('register_type') == 'invite') {
                         H::redirect_msg(AWS_APP::lang()->_t('本站只能通过邀请注册'));
                     } else {
                         if (get_setting('register_type') == 'weixin') {
                             H::redirect_msg(AWS_APP::lang()->_t('本站只能通过微信注册'));
                         } else {
                             $this->crumb(AWS_APP::lang()->_t('完善资料'), '/account/login/');
                             TPL::assign('user_name', AWS_APP::session()->sina_profile['screen_name']);
                             TPL::import_css('css/register.css');
                             TPL::output('account/openid/callback');
                         }
                     }
                 }
             }
         }
     }
 }