public function getAuthUrl() { $consumerKey = $this->getConsumerKey(); $consumerSecret = $this->getConsumerSecret(); $callback = YahooUtil::current_url() . '?in_popup'; return YahooSession::createAuthorizationUrl($consumerKey, $consumerSecret, $callback); }
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>"; } }
/** * @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); } } } }
define('OAUTH_CONSUMER_SECRET', '###'); define('OAUTH_DOMAIN', '###'); define('OAUTH_APP_ID', '###'); if (array_key_exists("logout", $_GET)) { // if a session exists and the logout flag is detected // clear the session tokens and reload the page. YahooSession::clearSession(); header("Location: sampleapp.php"); } // check for the existance of a session. // this will determine if we need to show a pop-up and fetch the auth url, // or fetch the user's social data. $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); if ($hasSession == FALSE) { // create the callback url, $callback = YahooUtil::current_url() . "?in_popup"; // pass the credentials to get an auth url. // this URL will be used for the pop-up. $auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback); } else { // pass the credentials to initiate a session $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID); // if the in_popup flag is detected, // the pop-up has loaded the callback_url and we can close this window. if (array_key_exists("in_popup", $_GET)) { close_popup(); exit; } // if a session is initialized, fetch the user's profile information if ($session) { // Get the currently sessioned user.
/** * Sets the presence of the user. * * @param $status The new status message for the user. * @return The status message on success, NULL on failure. * @deprecated As of 1.2, replaced by setStatus */ function setPresence($status) { global $YahooConfig; YahooLogger::info("setPresence is deprecated since 1.2: Please use setStatus"); if(!$this->sessioned) { YahooLogger::error("Can't set the presence of an unsessioned user"); return NULL; } $presence = array("status" => $status); $presence_json = json_encode($presence); $request_url = sprintf("https://%s/v1/user/%s/presence/presence", $YahooConfig["PRESENCE_WS_HOSTNAME"], $this->guid); $response = $this->client->put($request_url, "application/json", $presence_json); if(YahooUtil::is_response_error($response)) { return NULL; } $presence = json_decode($response["responseBody"]); return $presence; }