def validate(data_dict):
    '''
    Validates the given data and recaptcha if necessary.

    :param data_dict: the request params as a dict
    :return: a 3-tuple of errors, error summaries and a recaptcha error, in the event where no
             issues occur the return is ({}, {}, None)
    '''
    errors = {}
    error_summary = {}
    recaptcha_error = None

    # check the three fields we know about
    for field in ('email', 'name', 'content'):
        value = data_dict.get(field, None)
        if value is None or value == '':
            errors[field] = ['Missing Value']
            error_summary[field] = 'Missing value'

    # only check the recaptcha if there are no errors
    if not errors:
        try:
            expected_action = toolkit.config.get(
                'ckanext.contact.recaptcha_v3_action')
            # check the recaptcha value, this only does anything if recaptcha is setup
            recaptcha.check_recaptcha(
                data_dict.get('g-recaptcha-response', None), expected_action)
        except recaptcha.RecaptchaError as e:
            log.info(f'Recaptcha failed due to "{e}"')
            recaptcha_error = toolkit._(
                'Recaptcha check failed, please try again.')

    return errors, error_summary, recaptcha_error
    def _validate(self, data_dict):
        '''
        Validates the given data and recaptcha if necessary.

        :param data_dict: the request params as a dict
        :return: a 3-tuple of errors, error summaries and a recaptcha error, in the event where no
                 issues occur the return is ({}, {}, None)
        '''
        errors = {}
        error_summary = {}
        recaptcha_error = None

        # check the three fields we know about
        for field in (u'email', u'name', u'content'):
            value = data_dict.get(field, None)
            if value is None or value == u'':
                errors[field] = [u'Missing Value']
                error_summary[field] = u'Missing value'

        # only check the recaptcha if there are no errors
        if not errors:
            try:
                # check the recaptcha value, this only does anything if recaptcha is setup
                recaptcha.check_recaptcha(
                    data_dict.get(u'g-recaptcha-response', None),
                    self.expected_action)
            except recaptcha.RecaptchaError as e:
                log.info(u'Recaptcha failed due to "{}"'.format(e))
                recaptcha_error = _(
                    u'Recaptcha check failed, please try again.')

        return errors, error_summary, recaptcha_error
    def _validate(self, data_dict):
        '''
        Validates the given data and recaptcha if necessary.

        :param data_dict: the request params as a dict
        :return: a 3-tuple of errors, error summaries and a recaptcha error, in the event where no
                 issues occur the return is ({}, {}, None)
        '''
        errors = {}
        error_summary = {}
        recaptcha_error = None

        # check the three fields we know about
        for field in (u'email', u'name', u'content'):
            value = data_dict.get(field, None)
            if value is None or value == u'':
                errors[field] = [u'Missing Value']
                error_summary[field] = u'Missing value'

        # only check the recaptcha if there are no errors
        if not errors:
            try:
                # check the recaptcha value, this only does anything if recaptcha is setup
                recaptcha.check_recaptcha(data_dict.get(u'g-recaptcha-response', None),
                                          self.expected_action)
            except recaptcha.RecaptchaError as e:
                log.info(u'Recaptcha failed due to "{}"'.format(e))
                recaptcha_error = _(u'Recaptcha check failed, please try again.')

        return errors, error_summary, recaptcha_error