/**
  * Checks, if a valid auth code was submitted and invalidates it
  *
  * @return array the GET/POST data array
  */
 public function process()
 {
     $authCode = $this->utils->getAuthCode();
     if (empty($authCode)) {
         $this->utilityFuncs->throwException('validateauthcode_insufficient_params');
     }
     $authCodeData = $this->utils->getAuthCodeDataFromDB($authCode);
     if (!isset($authCodeData)) {
         $this->utilityFuncs->throwException('validateauthcode_no_record_found');
     }
     $this->utils->clearAuthCodeFromSession();
     $this->authCodeRepository->clearAssociatedAuthCodes($authCodeData);
     $this->gp = $this->utils->clearAuthCodeFromGP($this->gp);
     return $this->gp;
 }
 /**
  * Checks, if a valid auth code was submitted and if the submitted uid
  * matches the one that was used for generating the auth code
  *
  * @return array the GET/POST data array
  */
 public function process()
 {
     $authCode = $this->utils->getAuthCode();
     if (empty($authCode)) {
         $this->utilityFuncs->throwException('validateauthcode_insufficient_params');
     }
     $authCodeRecord = $this->utils->getAuthCodeDataFromDB($authCode);
     if (!isset($authCodeRecord)) {
         $this->utilityFuncs->throwException('validateauthcode_no_record_found');
     }
     $submittedIdentifier = $this->utilityFuncs->getSingle($this->settings, 'identifier');
     if (empty($submittedIdentifier)) {
         $this->utilityFuncs->throwException('The identifier mapping was not configured or the submitted identifier was empty.');
     }
     if ($submittedIdentifier !== $authCodeRecord->getIdentifier()) {
         $this->utilityFuncs->throwException('The submitted identifier ' . $submittedIdentifier . ' does not match the one the auth code was created for: ' . $authCodeRecord->getIdentifier());
     }
     return $this->gp;
 }
 /**
  * Checks, if a valid auth code was submitted and deletes the referenced record
  * from the database
  *
  * @return array the GET/POST data array
  */
 public function process()
 {
     $submittedAuthCode = $this->utils->getAuthCode();
     if (empty($submittedAuthCode)) {
         $this->utilityFuncs->throwException('validateauthcode_insufficient_params');
     }
     $authCode = $this->utils->getAuthCodeDataFromDB($submittedAuthCode);
     if (!isset($authCode)) {
         $this->utilityFuncs->throwException('validateauthcode_no_record_found');
     }
     $forceDeletion = TRUE;
     if (intval($this->settings['markAsDeleted'])) {
         $forceDeletion = FALSE;
     }
     $this->authCodeRecordRepository->removeAssociatedRecord($authCode, $forceDeletion);
     $this->authCodeRepository->clearAssociatedAuthCodes($authCode);
     $this->utils->clearAuthCodeFromSession();
     $this->gp = $this->utils->clearAuthCodeFromGP($this->gp);
     return $this->gp;
 }
 /**
  * Checks, if a valid auth code was submitted and if the submitted uid
  * matches the one that was used for generating the auth code
  *
  * @return array the GET/POST data array
  */
 public function process()
 {
     $authCode = $this->utils->getAuthCode();
     if (empty($authCode)) {
         $this->utilityFuncs->throwException('validateauthcode_insufficient_params');
     }
     $authCodeRecord = $this->utils->getAuthCodeDataFromDB($authCode);
     if (!isset($authCodeRecord)) {
         $this->utilityFuncs->throwException('validateauthcode_no_record_found');
     }
     $uidGP = $this->utilityFuncs->getSingle($this->settings, 'compareUid');
     if (!$uidGP) {
         $uidField = $authCodeRecord->getReferenceTableUidField();
         $uidGP = $this->gp[$uidField];
     }
     $uidGP = intval($uidGP);
     $uidAuthCode = $authCodeRecord->getReferenceTableUid();
     if ($uidGP !== $uidAuthCode) {
         $this->utilityFuncs->throwException('The submitted uid ' . $uidGP . ' does not match the one the auth code was created for: ' . $uidAuthCode);
     }
     return $this->gp;
 }
 /**
  * Inits the finisher mapping settings values to internal attributes.
  *
  * @param array $gp
  * @param array $settings
  * @throws MissingSettingException If not all requires settings have heen set
  * @return void
  */
 public function init($gp, $settings)
 {
     parent::init($gp, $settings);
     if (!isset($this->utils)) {
         $this->utils = AuthCodeUtils::getInstance();
     }
     if (!isset($this->objectManager)) {
         $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     }
     if (!isset($this->authCodeRepository)) {
         $this->authCodeRepository = $this->objectManager->get('Tx\\Authcode\\Domain\\Repository\\AuthCodeRepository');
     }
     if ($this->settings['independentMode']) {
         $this->independentMode = $this->utilityFuncs->getSingle($this->settings, 'independentMode');
     }
     if (!$this->independentMode) {
         if (!$this->settings['table']) {
             throw new MissingSettingException('table');
         } else {
             $this->table = (string) $this->utilityFuncs->getSingle($this->settings, 'table');
         }
         if ($this->settings['uidField']) {
             $this->uidField = $this->settings['uidField'];
         }
     }
     if (!empty($this->settings['action'])) {
         if ($this->settings['action'] === 'accessForm') {
             $this->utilityFuncs->debugMessage('Using the accessForm action for the GenerateAuthCodeDB finisher is deprecated! Use accessPage instead.', array(), 2);
             GeneralUtility::deprecationLog('formhandler_subscription: Using the accessForm action for the GenerateAuthCodeDB finisher is deprecated. Use accessPage instead.');
             $this->settings['action'] = AuthCodeAction::ACCESS_PAGE;
         }
         $this->action = $this->settings['action'];
     } else {
         $this->action = AuthCodeAction::RECORD_ENABLE;
     }
     $this->utils->checkAuthCodeAction($this->action);
     if ($this->settings['hiddenField']) {
         $this->hiddenField = $this->settings['hiddenField'];
     } elseif ($GLOBALS['TCA'][$this->table]['ctrl']['enablecolumns']['disabled']) {
         $this->hiddenField = $GLOBALS['TCA'][$this->table]['ctrl']['enablecolumns']['disabled'];
     } else {
         $this->hiddenField = 'hidden';
     }
 }
 /**
  * Inits the finisher mapping settings values to internal attributes.
  *
  * @param array $gp
  * @param array $settings
  * @return void
  */
 public function init($gp, $settings)
 {
     parent::init($gp, $settings);
     $this->typo3Db = $GLOBALS['TYPO3_DB'];
     $this->utils = AuthCodeUtils::getInstance();
 }
 /**
  * Checks the submitted auth code, executes the configured action and optionally
  * redirects the user to a success page if the auth code is valid.
  *
  * If the auth code is invalid an exception will be thrown or the user will be
  * redirected to a configured error page.
  *
  * @throws \Exception If the validation of the auth code fails and no error page was configured
  * @return array
  */
 public function process()
 {
     try {
         $submittedAuthCode = (string) $this->utils->getAuthCode();
         if ($submittedAuthCode === '') {
             if (!intval($this->settings['authCodeIsOptional'])) {
                 $this->utilityFuncs->throwException('validateauthcode_insufficient_params');
             } else {
                 return $this->gp;
             }
         }
         $authCode = $this->utils->getAuthCodeDataFromDB($submittedAuthCode);
         if (!isset($authCode)) {
             $this->utilityFuncs->throwException('validateauthcode_no_record_found');
         }
         $isAccessPageAction = $authCode->getAction() === AuthCodeAction::ACCESS_PAGE;
         if (intval($this->settings['doNotInvalidateAuthCode'])) {
             $this->authCodeValidator->setInvalidateAuthCodeAfterAccess(FALSE);
         } elseif (!isset($this->settings['doNotInvalidateAuthCode']) && $isAccessPageAction) {
             $this->utilityFuncs->debugMessage('Using auth code action "accessPage" (former "accessForm) will not automatically set "doNotInvalidateAuthCode" in future versions. You need to set this manually!', array(), 2);
             GeneralUtility::deprecationLog('formhandler_subscription: Using auth code action "accessPage" (former "accessForm) will not automatically set "doNotInvalidateAuthCode" in future versions. You need to set this manually!');
             $this->authCodeValidator->setInvalidateAuthCodeAfterAccess(FALSE);
         }
         try {
             $authCode = $this->authCodeValidator->validateAuthCodeAndExecuteAction($authCode);
         } catch (\Tx\Authcode\Exception\InvalidAuthCodeException $invalidAuthCodeException) {
             $this->utilityFuncs->throwException('validateauthcode_no_record_found');
         }
         if ($isAccessPageAction) {
             // Make the auth code available in the form so that it can be
             // submitted as a hidden field
             $this->gp['authCode'] = $submittedAuthCode;
             // Make the auth code data available so that it can be displayed to the user
             $this->gp['authCodeRecord'] = $authCode;
             if ($authCode->getType() === AuthCodeType::RECORD) {
                 // Make the auth code  record data available so that it can be displayed to the user
                 $authCodeRecordData = $this->authCodeRecordRepository->getAuthCodeRecordFromDB($authCode);
                 $this->gp['authCodeRecord'] = $authCodeRecordData;
                 if (intval($this->settings['mergeRecordDataToGP'])) {
                     $this->gp = array_merge($this->gp, $authCodeRecordData);
                 }
             } elseif ($authCode->getType() == AuthCodeType::INDEPENDENT) {
                 if (!empty($this->settings['mergeIndependentIdentifierToGP'])) {
                     $identifierMapping = (string) $this->settings['mergeIndependentIdentifierToGP'];
                     $this->gp[$identifierMapping] = $authCode->getIdentifier();
                 }
             }
             // Store the authCode in the session so that the user can use it
             // on different pages without the need to append it as a get
             // parameter everytime
             $this->utils->storeAuthCodeInSession($authCode->getAuthCode());
         }
         $redirectPage = $this->utilityFuncs->getSingle($this->settings, 'redirectPage');
         if ($redirectPage) {
             $this->utilityFuncs->doRedirect($redirectPage, $this->settings['correctRedirectUrl'], $this->settings['additionalParams.']);
             exit;
         }
     } catch (\Exception $e) {
         // Make sure, invalid auth codes are deleted.
         if (isset($authCode)) {
             $this->authCodeValidator->invalidateAuthCode($authCode);
         }
         $redirectPage = $this->utilityFuncs->getSingle($this->settings, 'errorRedirectPage');
         if ($redirectPage) {
             $this->utilityFuncs->doRedirect($redirectPage, $this->settings['correctRedirectUrl'], $this->settings['additionalParams.']);
             exit;
         } else {
             throw new \Exception($e->getMessage());
         }
     }
     return $this->gp;
 }