/** * Login to facebook and get the associated cloudrexx user. */ public function login() { // fixing timestamp issue with twitter // it is necessary that the twitter server has the same time as our system date_default_timezone_set('UTC'); $tmhOAuth = new \tmhOAuth(array('consumer_key' => $this->applicationData[0], 'consumer_secret' => $this->applicationData[1])); // set the timestamp $tmhOAuth->config['force_timestamp'] = true; $tmhOAuth->config['timestamp'] = time(); if (isset($_GET['oauth_verifier'])) { $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token']; $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret']; $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_GET['oauth_verifier'], 'x_auth_access_type' => 'read')); $access_token = $tmhOAuth->extract_params($tmhOAuth->response['response']); $tmhOAuth->config['user_token'] = $access_token['oauth_token']; $tmhOAuth->config['user_secret'] = $access_token['oauth_token_secret']; $tmhOAuth->request('GET', $tmhOAuth->url('1.1/account/verify_credentials')); $resp = json_decode($tmhOAuth->response['response']); unset($_SESSION['oauth']); $name = explode(' ', $resp->name); self::$userdata = array('first_name' => $name[0], 'last_name' => $name[1], 'email' => $resp->screen_name . '@twitter.com'); $this->getContrexxUser($resp->id); } else { $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ""), array('oauth_callback' => \Cx\Lib\SocialLogin::getLoginUrl(self::OAUTH_PROVIDER))); $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']); $url = 'https://api.twitter.com/oauth/authenticate?oauth_token=' . $_SESSION['oauth']['oauth_token']; \Cx\Core\Csrf\Controller\Csrf::header("Location: " . $url); exit; } }
/** * Login to facebook and get the associated cloudrexx user. */ public function login() { $client = new \Google_Client(); $client->setApplicationName('Contrexx Login'); $client->setClientId($this->applicationData[0]); $client->setClientSecret($this->applicationData[1]); $client->setRedirectUri(\Cx\Lib\SocialLogin::getLoginUrl(self::OAUTH_PROVIDER)); $client->setDeveloperKey($this->applicationData[2]); $client->setUseObjects(true); $client->setApprovalPrompt('auto'); $client->setScopes(self::$scopes); self::$google = new \Google_Oauth2Service($client); self::$googleplus = new \Google_PlusService($client); if (isset($_GET['code'])) { try { $client->authenticate(); } catch (\Google_AuthException $e) { } } if (!$client->getAccessToken()) { \Cx\Core\Csrf\Controller\Csrf::header('Location: ' . $client->createAuthUrl()); exit; } self::$userdata = $this->getUserData(); $this->getContrexxUser(self::$userdata['oauth_id']); }
/** * Parse the sociallogin login buttons in the template given. * * @static * @param $objTpl template object to parse * @param string $prefix the prefix for the template blocks and variables */ public static function parseSociallogin($objTpl, $prefix = 'login_') { $arrSettings = \User_Setting::getSettings(); if (function_exists('curl_init') && $arrSettings['sociallogin']['status'] && !isset($_SESSION['user_id'])) { if (!empty($_GET['redirect'])) { $_SESSION['redirect'] = $_GET['redirect']; } $redirect = isset($_SESSION['redirect']) ? $_SESSION['redirect'] : null; $socialloginProviders = \Cx\Lib\SocialLogin::getProviders(); foreach ($socialloginProviders as $provider => $providerData) { if (!$objTpl->blockExists($prefix . 'social_networks_' . $provider)) { continue; } $objTpl->setVariable(strtoupper($prefix) . 'SOCIALLOGIN_' . strtoupper($provider), contrexx_raw2xhtml(\Cx\Lib\SocialLogin::getLoginUrl($provider, $redirect))); if ($providerData->isActive()) { $objTpl->touchBlock($prefix . 'social_networks_' . $provider); } else { $objTpl->hideBlock($prefix . 'social_networks_' . $provider); } } } else { if ($objTpl->blockExists($prefix . 'social_networks')) { $objTpl->hideBlock($prefix . 'social_networks'); } } }
/** * Parse the network settings page * * @param object the user object of the current logged in user */ private function parseNetworks($objUser) { global $_ARRAYLANG; $availableProviders = \Cx\Lib\SocialLogin::getProviders(); foreach ($availableProviders as $index => $provider) { if (!$provider->isActive()) { unset($availableProviders[$index]); } } $userNetworks = $objUser->getNetworks()->getNetworksAsArray(); $this->_objTpl->setGlobalVariable(array('TXT_ACCESS_SOCIALLOGIN_PROVIDER' => $_ARRAYLANG['TXT_ACCESS_SOCIALLOGIN_PROVIDER'], 'TXT_ACCESS_SOCIALLOGIN_STATE' => $_ARRAYLANG['TXT_ACCESS_SOCIALLOGIN_STATE'])); // get current url for redirect parameter $currentUrl = clone \Env::get('Resolver')->getUrl(); if (!$this->_objTpl->blockExists('access_sociallogin_provider')) { return null; } // parse the connect buttons foreach ($availableProviders as $providerName => $providerSettings) { if (empty($userNetworks[$providerName])) { $state = $_ARRAYLANG['TXT_ACCESS_SOCIALLOGIN_DISCONNECTED']; $class = 'disconnected'; $uri = contrexx_raw2xhtml(\Cx\Lib\SocialLogin::getLoginUrl($providerName, base64_encode($currentUrl->__toString()))); $uriAction = $_ARRAYLANG['TXT_ACCESS_SOCIALLOGIN_CONNECT']; } else { $state = $_ARRAYLANG['TXT_ACCESS_SOCIALLOGIN_CONNECTED']; $class = 'connected'; $disconnectUrl = clone \Env::get('Resolver')->getUrl(); $disconnectUrl->setParam('act', 'disconnect'); $disconnectUrl->setParam('provider', $providerName); $uri = $disconnectUrl->__toString(); $uriAction = $_ARRAYLANG['TXT_ACCESS_SOCIALLOGIN_DISCONNECT']; } $this->_objTpl->setVariable(array('ACCESS_SOCIALLOGIN_PROVIDER_NAME_UPPER' => contrexx_raw2xhtml(ucfirst($providerName)), 'ACCESS_SOCIALLOGIN_PROVIDER_STATE' => $state, 'ACCESS_SOCIALLOGIN_PROVIDER_STATE_CLASS' => $class, 'ACCESS_SOCIALLOGIN_PROVIDER_NAME' => contrexx_raw2xhtml($providerName), 'ACCESS_SOCIALLOGIN_URL' => $uri, 'ACCESS_SOCIALLOGIN_URL_ACTION' => $uriAction)); if ($class == 'disconnected') { $this->_objTpl->parse('access_sociallogin_provider_disconnected'); $this->_objTpl->hideBlock('access_sociallogin_provider_connected'); } else { $this->_objTpl->parse('access_sociallogin_provider_connected'); $this->_objTpl->hideBlock('access_sociallogin_provider_disconnected'); } $this->_objTpl->parse('access_sociallogin_provider'); } }