Exemple #1
0
 /**
  * Perform login action
  *
  * @return void
  */
 protected function doActionLogin()
 {
     $loginApi = new \XLite\Module\CDev\Paypal\Core\Login();
     $requestProcessed = false;
     $returnURL = '';
     \XLite\Module\CDev\Paypal\Main::addLog('Login return', \XLite\Core\Request::getInstance()->getData());
     if ($loginApi->checkRequest()) {
         $accessToken = $loginApi->createFromAuthorisationCode(\XLite\Core\Request::getInstance()->code);
         $profileInfo = isset($accessToken['access_token']) ? $loginApi->getUserinfo($accessToken['access_token']) : null;
         if ($profileInfo && !empty($profileInfo['user_id']) && !empty($profileInfo['email'])) {
             $profile = $this->getSocialLoginProfile($profileInfo['email'], 'PayPal', $profileInfo['user_id'], $profileInfo);
             if ($profile) {
                 if ($profile->isEnabled()) {
                     \XLite\Core\Auth::getInstance()->loginProfile($profile);
                     $accessToken['expirationTime'] = LC_START_TIME + $accessToken['expires_in'];
                     \XLite\Core\Session::getInstance()->paypalAccessToken = $accessToken;
                     // We merge the logged in cart into the session cart
                     $profileCart = $this->getCart();
                     $profileCart->login($profile);
                     \XLite\Core\Database::getEM()->flush();
                     if ($profileCart->isPersistent()) {
                         $this->updateCart();
                     }
                     $returnURL = $this->getAuthReturnURL();
                 } else {
                     \XLite\Core\TopMessage::addError('Profile is disabled');
                     $returnURL = $this->getAuthReturnURL(true);
                 }
             } else {
                 $provider = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('login' => $profileInfo['email'], 'order' => null))->getSocialLoginProvider();
                 if ($provider) {
                     $signInVia = 'Please sign in with ' . $provider . '.';
                 } else {
                     $signInVia = 'Profile with the same e-mail address already registered. ' . 'Please sign in the classic way.';
                 }
                 \XLite\Core\TopMessage::addError($signInVia);
                 $returnURL = $this->getAuthReturnURL(true);
             }
             $requestProcessed = true;
         }
     }
     if (!$requestProcessed) {
         \XLite\Core\TopMessage::addError('We were unable to process this request');
         $returnURL = '';
     }
     $this->closePopup($returnURL);
 }