validateByName example


        if (empty($unsubscribe)) {
            $errorFlag = [];
            $config = Shopware()->Container()->get(Shopware_Components_Config::class);

            if ($this->shouldVerifyCaptcha($config)
                && (bool) $this->front->Request()->getParam('voteConfirmed', false) === false
            ) {
                /** @var CaptchaValidator $captchaValidator */
                $captchaValidator = Shopware()->Container()->get('shopware.captcha.validator');

                if (!$captchaValidator->validateByName($config->get('newsletterCaptcha')$this->front->Request())) {
                    return [
                        'code' => 7,
                    ];
                }
            }

            $fields = ['newsletter'];
            foreach ($fields as $field) {
                $fieldData = $this->front->Request()->getPost($field);
                if (isset($fieldData) && empty($fieldData)) {
                    $errorFlag[$field] = true;
                }

        $this->repository = $repository;
    }

    /** * Validates a Request using the currently configured captcha * * @return bool */
    public function validate(Enlight_Controller_Request_Request $request)
    {
        return $this->validateByName(
            $this->repository->getConfiguredCaptcha()->getName(),
            $request
        );
    }

    /** * Validates a custom captcha by the template name which has passed in the request * * @param string $name * * @return bool */


    /** * Validates the captcha in the request */
    private function validateCaptcha(string $captchaName, Enlight_Controller_Request_Request $request): bool
    {
        /** @var CaptchaValidator $captchaValidator */
        $captchaValidator = $this->container->get('shopware.captcha.validator');

        try {
            $isValid = $captchaValidator->validateByName($captchaName$request);
        } catch (CaptchaNotFoundException $exception) {
            $this->container->get('corelogger')->error($exception->getMessage());
            $isValid = $captchaValidator->validateByName('nocaptcha', $request);
        }

        if ($isValid) {
            return true;
        }

        return false;
    }

    

    public function sendResetPasswordConfirmationMail($email)
    {
        $snippets = Shopware()->Snippets()->getNamespace('frontend/account/password');
        if ($this->config->get(self::CONFIG_PASSWORD_RESET_CAPTCHA) !== NoCaptcha::CAPTCHA_METHOD) {
            if (!empty($this->config->get('CaptchaColor'))) {
                if (!$this->captchaValidator->validateByName($this->config->get(self::CONFIG_PASSWORD_RESET_CAPTCHA)$this->Request())) {
                    return [
                        'sErrorMessages' => [$snippets->get('captchaInvalid')],
                        'sErrorFlag' => ['sCaptcha' => true],
                    ];
                }
            }
        }

        if (empty($email)) {
            return [
                'sErrorMessages' => [$snippets->get('ErrorForgotMail')],
                
$session = $this->get('session');

        $sNotificatedArticles = $session->get('sNotificatedArticles', []);

        if (!empty($notifyOrderNumber)) {
            $captchaValidator = $this->get(CaptchaValidator::class);
            $config = $this->get(Shopware_Components_Config::class);

            if ($config->get(self::CONFIG_NOTIFY_CAPTCHA) !== NoCaptcha::CAPTCHA_METHOD) {
                if (!empty($config->get('CaptchaColor'))) {
                    if (!$captchaValidator->validateByName($config->get(self::CONFIG_NOTIFY_CAPTCHA)$action->Request())) {
                        $sError = true;
                        $action->View()->assign('NotifyCaptchaError', true);
                        $action->View()->assign('ShowNotification', true);
                    }
                }
            }

            $validator = $this->get(EmailValidator::class);
            if (empty($email) || !$validator->isValid($email)) {
                $sError = true;
                $action->View()->assign('NotifyEmailError', true);
            }
Home | Imprint | This part of the site doesn't use cookies.