/**
  * 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;
 }
 /**
  * Deletes the records that is referenced by the auth code from
  * the database
  *
  * @param array|\Tx\Authcode\Domain\Model\AuthCode $authCodeData
  * @param bool $markAsDeleted
  * @deprecated Since 0.7.0, will be removed in version 1.0.0, use AuthCodeRecordRepository instead.
  * @see \Tx\Authcode\Domain\Repository\AuthCodeRecordRepository::removeAssociatedRecord()
  */
 public function removeAuthCodeRecordFromDB($authCodeData, $markAsDeleted = FALSE)
 {
     if (is_array($authCodeData)) {
         $authCode = $this->authCodeRepository->findByUid($authCodeData['uid']);
     } elseif ($authCodeData instanceof \Tx\Authcode\Domain\Model\AuthCode) {
         $authCode = $authCodeData;
     } else {
         throw new \InvalidArgumentException('$authCodeData must either be an array or an instance of \\Tx\\Authcode\\Domain\\Model\\AuthCode');
     }
     $this->authCodeRecordRepository->removeAssociatedRecord($authCode, !$markAsDeleted);
 }
 /**
  * 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;
 }