Пример #1
0
 public function forwardAction()
 {
     JO_Session::clear('user_info_twitteroauth');
     JO_Session::clear('user_info_twitteroauth');
     JO_Session::clear('access_token_twitteroauth');
     JO_Session::get('twitter_oauth');
     $request = $this->getRequest();
     $next = '';
     if ($request->issetQuery('next')) {
         $next = '&next=' . urlencode(html_entity_decode($request->getQuery('next')));
     }
     if ($request->getQuery('twitter_fnc')) {
         $next .= '&twitter_fnc=' . $request->getQuery('twitter_fnc');
     }
     $twitteroauth = new Helper_Modules_Twitter();
     $request_token = $twitteroauth->getRequestToken(WM_Router::create($request->getBaseUrl() . '?controller=modules_twitter_login' . $next));
     $request_token_url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
     if ($twitteroauth->http_code == 200) {
         if (isset($request_token['oauth_token']) && $request_token['oauth_token_secret']) {
             JO_Session::set('twitter_oauth', $request_token);
             $this->redirect($request_token_url);
         }
     }
     $this->setViewChange('no_account');
     $page_login_trouble = Model_Pages::getPage(Helper_Config::get('page_login_trouble'));
     if ($page_login_trouble) {
         $this->view->page_login_trouble = array('title' => $page_login_trouble['title'], 'href' => WM_Router::create($request->getBaseUrl() . '?controller=pages&action=read&page_id=' . $page_login_trouble['page_id']));
     }
 }
Пример #2
0
 public function connectAction()
 {
     $request = $this->getRequest();
     $this->noLayout(true);
     $this->view->close_box = false;
     if (JO_Session::get('user[user_id]')) {
         $twitteroauth = new Helper_Modules_Twitter(null, null, JO_Session::get('twitter_oauth[oauth_token]'), JO_Session::get('twitter_oauth[oauth_token_secret]'));
         $user_data = JO_Session::get('user_info_twitteroauth');
         if (!$user_data || $user_data->errors) {
             $access_token = $twitteroauth->getAccessToken($request->getQuery('oauth_verifier'));
             $user_data = $twitteroauth->get('account/verify_credentials');
             JO_Session::set('user_info_twitteroauth', $user_data);
             JO_Session::set('access_token_twitteroauth', $access_token);
         } else {
             $user_data = JO_Session::get('user_info_twitteroauth');
         }
         $connectObject = new Model_Twitter_Login();
         $user_info = $connectObject->getDataByUserId(JO_Session::get('user[user_id]'));
         if ($user_data) {
             $connectObjectCheck = new Model_Twitter_Login($user_data->id);
             if ($connectObjectCheck->row) {
                 if ($connectObjectCheck->row['user_id'] == JO_Session::get('user[user_id]')) {
                     $enable_action = true;
                 } else {
                     $is_user = new Model_Users_User($connectObjectCheck->row['user_id']);
                     if (!$is_user->count()) {
                         $enable_action = true;
                         $connectObject->deleteDataByUserId($connectObjectCheck->row['user_id']);
                     } else {
                         $enable_action = $this->translate('There is another profile that is associated with your twitter account');
                     }
                 }
             } else {
                 $enable_action = true;
             }
             if ($enable_action === true) {
                 if ($user_info) {
                     if ($connectObject->deleteDataByUserId(JO_Session::get('user[user_id]'))) {
                         $this->view->close_box = true;
                     } else {
                         $this->view->close_box = true;
                     }
                 } else {
                     $res = $connectObject->insert(array('twitter_oauth_token' => JO_Session::get('twitter_oauth[oauth_token]'), 'twitter_oauth_token_secret' => JO_Session::get('twitter_oauth[oauth_token_secret]'), 'username' => $user_data->screen_name, 'user_id' => JO_Session::get('user[user_id]'), 'oauth_uid' => $user_data->id));
                     if ($res) {
                         $this->view->close_box = true;
                     } else {
                         $this->view->close_box = true;
                     }
                 }
             } else {
                 JO_Session::set('connect_error', $enable_action);
                 $this->view->close_box = true;
             }
         } else {
             $twitteroauth = new Helper_Modules_Twitter();
             $next = WM_Router::create($request->getBaseUrl() . '?controller=modules_twitter_connect&action=connect');
             $request_token = $twitteroauth->getRequestToken(WM_Router::create($request->getBaseUrl() . '?controller=modules_twitter_login&action=forward&twitter_fnc=connect&next=' . $next));
             $request_token_url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
             if ($twitteroauth->http_code == 200) {
                 if (isset($request_token['oauth_token']) && $request_token['oauth_token_secret']) {
                     JO_Session::set('twitter_oauth', $request_token);
                     $this->redirect($request_token_url);
                 }
             }
         }
     }
     $this->view->close_box = true;
 }