/** * @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); }
public function process($sProvider = '') { switch ($sProvider) { case 'paypal': $oPayPal = new PayPal($this->config->values['module.setting']['sandbox.enable']); if ($oPayPal->valid() && $this->httpRequest->postExists('item_number') && $this->httpRequest->postExists('custom')) { if ($this->oUserModel->updateMembership($this->httpRequest->post('item_number'), $this->httpRequest->post('custom', 'int'), $this->httpRequest->post('amount'), $this->dateTime->dateTime('Y-m-d H:i:s'))) { $this->_bStatus = true; // Status is OK // PayPal will call automatically the "notification()" method thanks its IPN feature and "notify_url" form attribute. } } unset($oPayPal); break; case 'stripe': if ($this->httpRequest->postExists('stripeToken')) { Framework\File\Import::lib('Service.Stripe.init'); // Import the Stripe library \Stripe\Stripe::setApiKey($this->config->values['module.setting']['stripe.secret_key']); $oCharge = \Stripe\Charge::create(array('source' => $this->httpRequest->post('stripeToken'), 'email' => $this->httpRequest->post('stripeEmail'))); if ($this->oUserModel->updateMembership($this->httpRequest->post('item_number'), $this->httpRequest->post('member_id', 'int'), $this->httpRequest->post('amount'), $this->dateTime->dateTime('Y-m-d H:i:s'))) { $this->_bStatus = true; // Status is OK $this->notification('Stripe'); // Add info into the log file } } break; case '2co': $o2CO = new TwoCO($this->config->values['module.setting']['sandbox.enable']); $sVendorId = $this->config->values['module.setting']['2co.vendor_id']; $sSecretWord = $this->config->values['module.setting']['2co.secret_word']; if ($o2CO->valid($sVendorId, $sSecretWord) && $this->httpRequest->postExists('sale_id')) { if ($this->oUserModel->updateMembership($this->httpRequest->post('sale_id'), $this->iProfileId, $this->httpRequest->post('price'), $this->dateTime->dateTime('Y-m-d H:i:s'))) { $this->_bStatus = true; // Status is OK $this->notification('TwoCO'); // Add info into the log file } } unset($o2CO); break; case 'ccbill': // In developing... // Contact us at <*****@*****.**> if you want to help us develop the payment system CCBill break; default: $this->displayPageNotFound(t('Provinder Not Found!')); } // Set the page titles $this->sTitle = $this->_bStatus ? t('Thank you!') : t('Error occurred!'); $this->view->page_title = $this->sTitle; $this->view->h2_title = $this->sTitle; if ($this->_bStatus) { $this->updateAffCom(); } // Set the valid page $sPage = $this->_bStatus ? 'success' : 'error'; $this->manualTplInclude($sPage . $this->view->getTplExt()); // Output $this->output(); }