/**
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     // Import the library
     Import::lib('Service.Twitter.tmhOAuth');
     Import::lib('Service.Twitter.tmhUtilities');
     $this->_oTwOAuth = new \tmhOAuth(Config::getInstance()->values['module.api']['twitter.consumer_key'], Config::getInstance()->values['module.api']['twitter.consumer_secret_key']);
     // determine the authentication status
     // default to 0
     $this->_iState = 0;
     if (isset($_COOKIE['access_token'], $_COOKIE['access_token_secret'])) {
         // 2 (authenticated) if the cookies are set
         $this->_iState = 2;
     } elseif (isset($_SESSION['authstate'])) {
         // otherwise use value stored in session
         $this->_iState = (int) $_SESSION['authstate'];
     }
     if ($this->_iState == 1) {
         // if we are in the process of authentication we continue
         $this->auth();
     } elseif ($this->_iState == 2 && !$this->auth()) {
         // verify authentication, clearing cookies if it fails
         $this->endSession();
     }
     if ($this->auth()) {
         $aProfile = $this->_oTwOAuth->extract_params($this->_oTwOAuth->response['response']);
         if (empty($aProfile['error'])) {
             // User info is ok? Here we will be connect the user and/or adding the login and registering routines...
             $oUserModel = new UserCoreModel();
             if (!($iId = $oUserModel->getId($aProfile['email']))) {
                 // Add User if it does not exist in our database
                 $this->add(escape($aProfile, true), $oUserModel);
                 // Add User Avatar
                 $this->setAvatar($aProfile);
                 $this->oDesign->setFlashMsg(t('You have now been registered! %0%', (new Registration())->sendMail($this->_aUserInfo, true)->getMsg()));
                 $this->sUrl = Uri::get('connect', 'main', 'register');
             } else {
                 // Login
                 $this->setLogin($iId, $oUserModel);
                 $this->sUrl = Uri::get('connect', 'main', 'home');
             }
             unset($oUserModel);
         } else {
             // For testing purposes, if there was an error, let's kill the script
             $this->oDesign->setFlashMsg(t('Oops! An error has occurred. Please try again later.'));
             $this->sUrl = Uri::get('connect', 'main', 'index');
         }
     } else {
         $this->sUrl = Uri::get('connect', 'main', 'index');
     }
 }
 /**
  * Constructor.
  *
  * @param object \PH7\Framework\Session\Session $oSession
  * @param object \PH7\Framework\Mvc\Request\Http $oHttpRequest
  * @param object \PH7\Framework\Registry\Registry $oRegistry
  * @return void
  */
 public function __construct(Session $oSession, HttpRequest $oHttpRequest, Registry $oRegistry)
 {
     parent::__construct();
     /*** Import the libraries ***/
     Import::lib('Service.Google.OAuth.Google_Client');
     Import::lib('Service.Google.OAuth.contrib.Google_Oauth2Service');
     $oClient = new \Google_Client();
     $oClient->setApplicationName($oRegistry->site_name);
     $this->_setConfig($oClient);
     $oOauth = new \Google_Oauth2Service($oClient);
     if ($oHttpRequest->getExists('code')) {
         $oClient->authenticate();
         $oSession->set('token', $oClient->getAccessToken());
         $this->sUrl = Uri::get('connect', 'main', 'home');
     }
     if ($oSession->exists('token')) {
         $oClient->setAccessToken($oSession->get('token', false));
     }
     if ($oClient->getAccessToken()) {
         // User info is ok? Here we will be connect the user and/or adding the login and registering routines...
         $oUserModel = new UserCoreModel();
         // Get information of user
         $aUserData = $oOauth->userinfo->get();
         if (!($iId = $oUserModel->getId($aUserData['email']))) {
             // Add User if it does not exist in our database
             $this->add(escape($aUserData, true), $oUserModel);
             // Add User Avatar
             if (!empty($aUserData['picture'])) {
                 $this->setAvatar($aUserData['picture']);
             }
             $this->oDesign->setFlashMsg(t('You have now been registered! %0%', (new Registration())->sendMail($this->_aUserInfo, true)->getMsg()));
             $this->sUrl = Uri::get('connect', 'main', 'register');
         } else {
             // Login
             $this->setLogin($iId, $oUserModel);
             $this->sUrl = Uri::get('connect', 'main', 'home');
         }
         // Add the access token
         $oSession->set('token', $oClient->getAccessToken());
         unset($oUserModel);
     } else {
         $this->sUrl = $oClient->createAuthUrl();
     }
     unset($oClient, $oOauth);
 }
 /**
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     // Import the library
     Import::lib('Service.Microsoft.Live.oauth_client');
     Import::lib('Service.Microsoft.Live.http');
     $this->_oClient = new \oauth_client_class();
     $this->_setConfig();
     /* API permissions */
     $this->_oClient->scope = 'wl.basic wl.emails wl.birthday';
     if ($bSuccess = $this->_oClient->Initialize()) {
         if ($bSuccess = $this->_oClient->Process()) {
             if (strlen($this->_oClient->authorization_error)) {
                 $this->_oClient->error = $this->_oClient->authorization_error;
                 $bSuccess = false;
             } elseif (strlen($this->_oClient->access_token)) {
                 $bSuccess = $this->_oClient->CallAPI('https://apis.live.net/v5.0/me', 'GET', array(), array('FailOnAccessError' => true), $oUserData);
             }
         }
         $bSuccess = $this->_oClient->Finalize($bSuccess);
     }
     if ($this->_oClient->exit) {
         exit(1);
     }
     if ($bSuccess) {
         // User info is ok? Here we will be connect the user and/or adding the login and registering routines...
         $oUserModel = new UserCoreModel();
         if (!($iId = $oUserModel->getId($oUserData->emails->account))) {
             // Add User if it does not exist in our database
             $this->add(escape($oUserData, true), $oUserModel);
             $this->oDesign->setFlashMsg(t('You have now been registered! %0%', (new Registration())->sendMail($this->_aUserInfo, true)->getMsg()));
             $this->sUrl = Uri::get('connect', 'main', 'register');
         } else {
             // Login
             $this->setLogin($iId, $oUserModel);
             $this->sUrl = Uri::get('connect', 'main', 'home');
         }
         unset($oUserModel);
     } else {
         // For testing purposes, if there was an error, let's kill the script
         $this->oDesign->setFlashMsg(t('Oops! An error has occurred. Please try again later.'));
         $this->sUrl = Uri::get('connect', 'main', 'index');
     }
 }
 /**
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     Import::lib('Service.Facebook.Facebook');
     // Import the library
     $oFb = new \Facebook(array('appId' => Config::getInstance()->values['module.api']['facebook.id'], 'secret' => Config::getInstance()->values['module.api']['facebook.secret_key']));
     $sUserId = $oFb->getUser();
     if ($sUserId) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $aProfile = $oFb->api('/me');
         } catch (\FacebookApiException $oE) {
             Framework\Error\CException\PH7Exception::launch($oE);
             $sUserId = null;
         }
         if ($aProfile) {
             // User info is ok? Here we will be connect the user and/or adding the login and registering routines...
             $oUserModel = new UserCoreModel();
             if (!($iId = $oUserModel->getId($aProfile['email']))) {
                 // Add User if it does not exist in our database
                 $this->add(escape($aProfile, true), $oUserModel);
                 // Add User Avatar
                 $this->setAvatar($sUserId);
                 $this->oDesign->setFlashMsg(t('You have now been registered! %0%', (new Registration())->sendMail($this->_aUserInfo, true)->getMsg()));
                 $this->sUrl = Uri::get('connect', 'main', 'register');
             } else {
                 // Login
                 $this->setLogin($iId, $oUserModel);
                 $this->sUrl = Uri::get('connect', 'main', 'home');
             }
             unset($oUserModel);
         } else {
             // For testing purposes, if there was an error, let's kill the script
             $this->oDesign->setFlashMsg(t('Oops! An error has occurred. Please try again later.'));
             $this->sUrl = Uri::get('connect', 'main', 'index');
         }
     } else {
         // There's no active session, let's generate one
         $this->sUrl = $oFb->getLoginUrl(array('scope' => 'email,user_birthday,user_relationships,user_relationship_details,user_hometown,user_location,user_interests,user_about_me,user_likes,user_website'));
     }
     unset($oFb);
 }