Пример #1
0
 public function __construct()
 {
     require Mage::getBaseDir('lib') . DS . 'Magegiant' . DS . 'Yahoo' . DS . 'Yahoo.inc';
     error_reporting(E_ALL | E_NOTICE);
     # do not show notices as library is php4 compatable
     ini_set('display_errors', true);
     YahooLogger::setDebug(true);
     YahooLogger::setDebugDestination('LOG');
     // use memcache to store oauth credentials via php native sessions
     ini_set('session.save_handler', 'files');
     session_save_path('/tmp/');
     session_start();
     if (array_key_exists("logout", $_GET)) {
         YahooSession::clearSession();
         //$this->reloadPage();
     }
 }
Пример #2
0
 public function __construct()
 {
     try {
         require Mage::getBaseDir('lib') . DS . 'Yahoo' . DS . 'Yahoo.inc';
     } catch (Exception $e) {
     }
     error_reporting(E_ALL | E_NOTICE);
     ini_set('display_errors', true);
     YahooLogger::setDebug(true);
     YahooLogger::setDebugDestination('LOG');
     ini_set('session.save_handler', 'files');
     session_save_path('/tmp/');
     session_start();
     if (array_key_exists("logout", $_GET)) {
         YahooSession::clearSession();
     }
 }
Пример #3
0
<?php
define('AUTH_SERVICE', 'yahoo');

require_once '../../key.php';
require_once '../server.php';

// Include the YOS library.
require 'lib/Yahoo.inc.php';
// Place Your App ID here

if (array_key_exists("logout", $_GET))
{
	YahooSession::clearSession();
	unset($_SESSION['login']);
	header("Location: index.php");
}
else
{
	$session = YahooSession::requireSession(YAHOO_CONSUMER_KEY, YAHOO_CONSUMER_SECRET, YAHOO_APP_ID);	
	if (is_object($session))
	{
		$user = $session -> getSessionedUser();
		$friend = $user -> getContacts(0, 5000);
		$aContactList = array();
		if ($friend -> contacts -> count > 0)
		{
			foreach ($friend->contacts->contact as $oContact)
			{
				$sEmail = $sUsername = '';
				foreach ($oContact->fields as $aField)
				{
 /**
  * @Yahoo login action
  *
  * Connect Yahoo Using oAuth coonection.
  *
  * @return string URL eiether customer save and loggedin or an error if any occurs
  */
 public function yahoopostAction()
 {
     /**
      * Include @Yahoo library files for oAuth connection
      */
     require 'sociallogin/lib/Yahoo.inc';
     YahooLogger::setDebug(true);
     YahooLogger::setDebugDestination('LOG');
     /**
      *
      * @param string $yahoo_client_id,
      *            $yahoo_client_secret and $yahoo_developer_key
      *            
      *            Using this params setting up the connection to yahoo
      */
     $yahooClientId = Mage::getStoreConfig('sociallogin/yahoo/yahoo_id');
     $yahooClientSecret = Mage::getStoreConfig('sociallogin/yahoo/yahoo_secret');
     $yahooDeveloperKey = Mage::getStoreConfig('sociallogin/yahoo/yahoo_develop');
     $yahooDomain = Mage::getUrl();
     /**
      * Use memcache to store oauth credentials via php native sessions
      *
      * Make sure you obtain application keys before continuing by visiting:<https://developer.yahoo.com/dashboard/createKey.html>
      */
     define('OAUTH_CONSUMER_KEY', "{$yahooClientId}");
     define('OAUTH_CONSUMER_SECRET', "{$yahooClientSecret}");
     define('OAUTH_DOMAIN', "{$yahooDomain}");
     define('OAUTH_APP_ID', "{$yahooDeveloperKey}");
     $para = $this->getRequest()->getParams();
     $data = $this->getRequest()->getParam('fb');
     if (array_key_exists("logout", $para)) {
         YahooSession::clearSession();
         $url = "index.php";
         $this->_redirectUrl($url);
     }
     $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
     YahooUtil::current_url();
     if (!$hasSession) {
         $callback = YahooUtil::current_url() . "?in_popup";
         $sessionStore = new NativeSessionStore();
         $authUrl = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, $sessionStore);
         if ($authUrl) {
             $this->_redirectUrl($authUrl);
         }
     } else {
         $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
         if ($session) {
             $user = $session->getSessionedUser();
             $profile = $user->getProfile();
             $profile->guid;
             $email = $profile->emails[0]->handle;
             $firstName = $profile->givenName;
             $lastName = $profile->familyName;
             if ($email == '') {
                 Mage::getSingleton('customer/session')->addError($this->__('Yahoo Login connection failed'));
                 $url = Mage::helper('customer')->getAccountUrl();
                 return $this->_redirectUrl($url);
             } else {
                 $this->customerAction($firstName, $lastName, $email, 'Yahoo', $data);
             }
         }
     }
 }
Пример #5
0
 public function saveAction()
 {
     require 'Yahoo/Yahoo.inc';
     $helper = Mage::helper('referralreward');
     //YahooLogger::setDebug(true);
     //YahooLogger::setDebugDestination('LOG');
     define('OAUTH_CONSUMER_KEY', $helper->storeConfig('yahoo/key'));
     define('OAUTH_CONSUMER_SECRET', $helper->storeConfig('yahoo/secret'));
     define('OAUTH_DOMAIN', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
     define('OAUTH_APP_ID', $helper->storeConfig('yahoo/appid'));
     $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
     if ($hasSession == FALSE) {
         $callback = YahooUtil::current_url() . "?in_popup";
         $sessionStore = new NativeSessionStore();
         $authUrl = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, $sessionStore);
         header("Location: " . $authUrl);
         exit;
     } else {
         $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
         if ($session) {
             $user = $session->getSessionedUser();
             //$profile = $user->getProfile();
             $contacts = $user->getContactSync();
             if ($contacts) {
                 $contacts = $this->XmltoArray($contacts);
                 $names = array();
                 $emails = array();
                 foreach ($contacts['contactsync']['contacts'] as $key => $profileContact) {
                     foreach ($profileContact['fields'] as $contact) {
                         $emails[] = $contact['value'];
                         $names[] = '';
                     }
                 }
                 YahooSession::clearSession();
                 $customer_id = (int) $this->_getSession()->getId();
                 $count = Mage::getModel('referralreward/friends')->saveFriends($customer_id, $emails, $names);
                 if ($count['enable']) {
                     if ($count['enable'] > 1) {
                         $this->_getSession()->addSuccess($this->__('%s have been added', $count['enable']));
                     } else {
                         $this->_getSession()->addSuccess($this->__('%s has been added', $count['enable']));
                     }
                 }
                 if ($count['disable']) {
                     $this->_getSession()->addSuccess($this->__('%s already registered', $count['disable']));
                 }
                 if ($count['enable'] == 0 && $count['disable'] == 0) {
                     $this->_getSession()->addError($this->__("no emails were added"));
                 }
             } else {
                 $this->_getSession()->addError($this->__("no emails were added"));
             }
         }
         echo "<script>\n                    window.opener.location.reload(true);\n                    window.close();\n                </script>";
     }
 }
Пример #6
0
    /**
     * @private
     */
    function initSession($consumerKey, $consumerSecret, $applicationId, $redirect, $callback, $sessionStore, $verifier)
    {
        global $GLOBAL_YAHOO_SESSION;

        if(!is_null($GLOBAL_YAHOO_SESSION)) {
            return $GLOBAL_YAHOO_SESSION;
        }

        $consumer = new stdclass();
        $consumer->key = $consumerKey;
        $consumer->secret = $consumerSecret;

        $checkSession = YahooSession::checkSession($type, $sessionStore);
        
        if(!$checkSession) {
            // There doesn't appear to be a session here.
            if($redirect)  {
                $GLOBAL_YAHOO_SESSION = NULL;
                YahooSession::redirectForAuthorization($consumerKey, $consumerSecret, $callback, $sessionStore);
            }
            else {
                // Don't redirect the user, just inform the caller that
                // no session is present.
                // TODO: throw a YahooException
                $GLOBAL_YAHOO_SESSION = NULL;
            }
        }
        else if($type == YAHOO_OAUTH_AT_SESSION_TYPE) {
            // Found an OAuth Access Token session.
            $accessToken = $sessionStore->fetchAccessToken();
            $now = time();

            YahooLogger::debug("OAuth AT: " . $accessToken->key . "   ATS: ". $accessToken->secret);

            if($accessToken->consumer != $consumerKey)
            {
                YahooLogger::error("Consumer key for token does not match the defined Consumer Key. The Consumer Key has probably changed since the user last authorized the application.");
                YahooSession::clearSession($sessionStore);

                if($redirect) {
                    YahooSession::redirectForAuthorization($consumerKey, $consumerSecret, $callback, $sessionStore);
                }
            }

            if($accessToken->tokenExpires >= 0) {
                YahooLogger::debug('AT Expires in: ' . ($accessToken->tokenExpires - $now));
            }

            if(($accessToken->tokenExpires >= 0) && ($accessToken->tokenExpires - $now) < 30) {
                // The access token will expire in less than 30 seconds or
                // it may have expired already. Try to get a new one.
                YahooSession::accessTokenExpired($accessToken, $consumer, $applicationId, $sessionStore);
            }
            else {
                // The access token is still good for a little while, continue using it.
                $GLOBAL_YAHOO_SESSION = new YahooSession($consumer, $accessToken, $applicationId);
            }
        }
        else if($type == YAHOO_OAUTH_RT_SESSION_TYPE)
        {
            if(is_null($verifier)) {
                // Can't proceed without the oauth_verifier, treat it as
                // though there's no session present.
                $sessionStore->clearRequestToken();

                // TODO: throw a YahooException
                $GLOBAL_YAHOO_SESSION = NULL;
            }

            // Found an OAuth Request Token session.
            $requestToken = $sessionStore->fetchRequestToken();

            $accessToken = YahooAuthorization::getAccessToken($consumerKey, $consumerSecret, $requestToken, $verifier);

            if(!is_null($accessToken)) {
                $sessionStore->storeAccessToken($accessToken);
                $sessionStore->clearRequestToken();

                $GLOBAL_YAHOO_SESSION = new YahooSession($consumer, $accessToken, $applicationId);
            }
            else if($redirect)
            {
                // TODO: Add redirect counter so this doesn't happen over and over and over when Yahoo! is completely busted.
                // The fetch for the access token failed. Generate a new
                // request token and try again.
                $GLOBAL_YAHOO_SESSION = NULL;
                YahooSession::redirectForAuthorization($consumerKey, $consumerSecret, $callback, $sessionStore);
            }
            else
            {
                // Don't redirect the user, just inform the caller that
                // no session is present.
                $sessionStore->clearRequestToken();
                $GLOBAL_YAHOO_SESSION = NULL;
            }
        }
        else if($type == YAHOO_YAP_SESSION_TYPE)
        {
            // Found a YAP session.
            $GLOBAL_YAHOO_SESSION = YahooSession::initSessionFromYAP($consumerKey, $consumerSecret, $applicationId);
        }
        else
        {
            YahooLogger::error("Unknown session type found");
            // TODO: throw a YahooException
            $GLOBAL_YAHOO_SESSION = NULL;
        }

        return $GLOBAL_YAHOO_SESSION;
    }