public function userAction() { $otwitter = Mage::getModel('sociallogin/twlogin'); $requestToken = Mage::getSingleton('core/session')->getRequestToken(); $oauth_data = array('oauth_token' => $this->getRequest()->getParam('oauth_token'), 'oauth_verifier' => $this->getRequest()->getParam('oauth_verifier')); $token = $otwitter->getAccessToken($oauth_data, unserialize($requestToken)); $params = array('consumerKey' => Mage::helper('sociallogin')->getTwConsumerKey(), 'consumerSecret' => Mage::helper('sociallogin')->getTwConsumerSecret(), 'accessToken' => $token); $twitter = new Zend_Service_Twitter($params); $response = $twitter->userShow($token->user_id); $twitterId = (string) $response->id; // get twitter account ID $customerId = $this->getCustomerId($twitterId); if ($customerId) { //login $customer = Mage::getModel('customer/customer')->load($customerId); Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer); die("<script type=\"text/javascript\">try{window.opener.location.reload(true);}catch(e){window.opener.location.href=\"" . Mage::getBaseUrl() . "\"} window.close();</script>"); } else { // redirect to login page Mage::getSingleton('core/session')->setTwitterId($twitterId); $connectingNotice = Mage::helper('sociallogin')->getTwConnectingNotice(); $storeName = Mage::app()->getStore()->getName(); Mage::getSingleton('core/session')->addNotice(str_replace('{{store}}', $storeName, $connectingNotice)); $nextUrl = Mage::helper('sociallogin')->getLoginUrl(); $backUrl = Mage::getSingleton('core/session')->getBackUrl(); Mage::getSingleton('customer/session')->setBeforeAuthUrl($backUrl); // after login redirect to current url die("<script>window.close();window.opener.location = '{$nextUrl}';</script>"); } }