예제 #1
0
 def test_verifier_false(self):
     """ test that verify_honeypot_value fails when HONEYPOT_VERIFIER returns False """
     request = _get_POST_request()
     request.POST[settings.HONEYPOT_FIELD_NAME] = ""
     settings.HONEYPOT_VERIFIER = lambda x: False
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp.__class__, HttpResponseBadRequest)
예제 #2
0
 def test_honeypot_value_callable(self):
     """ test that verify_honeypot_value succeeds when HONEYPOT_VALUE is a callable """
     request = _get_POST_request()
     settings.HONEYPOT_VALUE = lambda: '(test string)'
     request.POST[settings.HONEYPOT_FIELD_NAME] = settings.HONEYPOT_VALUE()
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp, None)
예제 #3
0
 def test_honeypot_value_string(self):
     """ test that verify_honeypot_value succeeds when HONEYPOT_VALUE is a string """
     request = _get_POST_request()
     settings.HONEYPOT_VALUE = '(test string)'
     request.POST[settings.HONEYPOT_FIELD_NAME] = settings.HONEYPOT_VALUE
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp, None)
예제 #4
0
 def test_verifier_false(self):
     """ test that verify_honeypot_value fails when HONEYPOT_VERIFIER returns False """
     request = _get_POST_request()
     request.POST[settings.HONEYPOT_FIELD_NAME] = ''
     settings.HONEYPOT_VERIFIER = lambda x: False
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp.__class__, HttpResponseBadRequest)
예제 #5
0
 def test_honeypot_value_callable(self):
     """ test that verify_honeypot_value succeeds when HONEYPOT_VALUE is a callable """
     request = _get_POST_request()
     settings.HONEYPOT_VALUE = lambda: "(test string)"
     request.POST[settings.HONEYPOT_FIELD_NAME] = settings.HONEYPOT_VALUE()
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp, None)
예제 #6
0
 def post(self, request, *args, **kwargs):
     from django.conf import settings
     honeypot_fieldname = self.honeypot_fieldname or getattr(
         settings, 'HONEYPOT_FIELD_NAME', 'family_name')
     response = verify_honeypot_value(request, honeypot_fieldname)
     if response:
         return response
     return super(HoneypotMixin, self).post(request, *args, **kwargs)
예제 #7
0
    def dispatch(self, request, *args, **kwargs):
        is_yari_signup = request.session.get("yari_signup", False)
        if not is_yari_signup:
            response = verify_honeypot_value(request, None)
            if isinstance(response, HttpResponseBadRequest):
                return response

        return super(SignupView, self).dispatch(request, *args, **kwargs)
예제 #8
0
def check_honeypot(request, form):
    u"""
    Make sure that the hidden form field is empty, using django-honeypot.
    """
    try:
        from honeypot.decorators import verify_honeypot_value
        return verify_honeypot_value(request, '') is None
    except ImportError:
        return True
예제 #9
0
def check_honeypot(request, form):
    """
    Make sure that the hidden form field is empty, using django-honeypot.
    """
    try:
        from honeypot.decorators import verify_honeypot_value
        return verify_honeypot_value(request, '') is None
    except ImportError:  # pragma: no cover
        return True
예제 #10
0
파일: views.py 프로젝트: sunlightlabs/act
    def post(self, request):

        # check honeypot value manually
        honeypot = verify_honeypot_value(request, settings.HONEYPOT_FIELD_NAME)
        if honeypot:
            return honeypot

        # check for form validity
        form = self.form_class(request.POST)
        if form.is_valid():
            # send message on valid form submission
            self.send_message(request, form.cleaned_data)
            # notify user of success and redirect
            messages.success(request, 'Thanks you for contacting us!')
            return HttpResponseRedirect(
                MESSAGE_SENT_URL if MESSAGE_SENT_URL else request.path)

        # form was not valid, show errors to user
        return render_to_response('hello/form.html', {'form': form},
                                  context_instance=RequestContext(request))
예제 #11
0
 def process_view(self, request, callback, callback_args, callback_kwargs):
     if request.is_ajax():
         return None
     if getattr(callback, 'honeypot_exempt', False):
         return None
     return verify_honeypot_value(request, None)
예제 #12
0
 def test_field_missing(self):
     """ test that verify_honeypot_value succeeds when HONEYPOT_FIELD_NAME is missing from request.POST """
     request = _get_POST_request()
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp.__class__, HttpResponseBadRequest)
예제 #13
0
 def test_field_blank(self):
     """ test that verify_honeypot_value succeeds when HONEYPOT_VALUE is blank """
     request = _get_POST_request()
     request.POST[settings.HONEYPOT_FIELD_NAME] = ''
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp, None)
예제 #14
0
 def test_no_call_on_get(self):
     """ test that verify_honeypot_value is not called when request.method == GET """
     request = _get_GET_request()
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp, None)
예제 #15
0
    def __call__(self, request, *args, **kwargs):
        """A view displaying a form, or JSON if request is AJAX."""
        obj = self.get_object(request, *args, **kwargs)
        form_args, form_kwargs = self.form_args(request, obj)
        if self.form_prefix:
            form_kwargs['prefix'] = self.form_prefix

        if request.method == "POST":
            if self.honeypot:
                response = verify_honeypot_value(request, None)
                if response:
                    return response

            # do I need to be logged in?
            if self.POST_login and not request.user.is_authenticated():
                return require_login(request)

            form_kwargs['data'] = request.POST
            form = self.form_class(*form_args, **form_kwargs)
            if form.is_valid():
                add_args = self.success(form, request)
                response_data = {
                    'success': True,
                    'message': self.success_message,
                    'redirect': request.GET.get('next')
                }
                if add_args:
                    response_data.update(add_args)
                if not request.is_ajax() and response_data['redirect']:
                    return HttpResponseRedirect(
                        urlquote_plus(response_data['redirect'], safe='/?=&'))
            elif request.is_ajax():
                # Form was sent with errors. Send them back.
                if self.form_prefix:
                    errors = {}
                    for key, value in form.errors.items():
                        errors["%s-%s" % (self.form_prefix, key)] = value
                else:
                    errors = form.errors
                response_data = {'success': False, 'errors': errors}
            else:
                response_data = None
            if request.is_ajax():
                return HttpResponse(
                    LazyEncoder(ensure_ascii=False).encode(response_data))
        else:
            if self.POST_login and not request.user.is_authenticated(
            ) and not request.is_ajax():
                return require_login(request)

            form = self.form_class(*form_args, **form_kwargs)
            response_data = None

        title = self.title
        if request.is_ajax():
            template = self.template
        else:
            template = self.full_template
            cd = self.context_description(request, obj)
            if cd:
                title += ": " + cd
        if self.placeholdize:
            form = placeholdized(form)
        context = {
            self.formname: form,
            "title": title,
            "honeypot": self.honeypot,
            "placeholdize": self.placeholdize,
            "submit": self.submit,
            "action": self.action,
            "response_data": response_data,
            "ajax_template": self.template,
            "view_args": args,
            "view_kwargs": kwargs,
        }
        context.update(self.extra_context(request, obj))
        return render_to_response(template,
                                  context,
                                  context_instance=RequestContext(request))
예제 #16
0
 def inner(request, *args, **kwargs):
     response = verify_honeypot_value(request, field_name)
     if response:
         return response
     else:
         return func(request, *args, **kwargs)
예제 #17
0
 def dispatch(self, request, *args, **kwargs):
     response = verify_honeypot_value(request, None)
     if isinstance(response, HttpResponseBadRequest):
         return response
     return super(SignupView, self).dispatch(request, *args, **kwargs)
예제 #18
0
 def process_view(self, request, callback, callback_args, callback_kwargs):
     if request.is_ajax():
         return None
     if getattr(callback, 'honeypot_exempt', False):
         return None
     return verify_honeypot_value(request, None)
예제 #19
0
 def process_view(self, request, callback, callback_args, callback_kwargs):
     if not honeypot_required(request):
         return None
     if request.is_ajax():
         return None
     return verify_honeypot_value(request, None)
예제 #20
0
def check_honeypot(request, form):
    u"""
    Make sure that the hidden form field is empty, using django-honeypot.
    """
    return verify_honeypot_value(request, '') is None
예제 #21
0
 def process_view(self, request, callback, callback_args, callback_kwargs):
     if request.is_ajax() or request.path_info in getattr(settings, 'HONEYPOT_SKIP_URLS', []):
         return None
     return verify_honeypot_value(request, None)
예제 #22
0
 def inner(request, *args, **kwargs):
     response = verify_honeypot_value(request, field_name)
     if response:
         return response
     else:
         return func(request, *args, **kwargs)
예제 #23
0
 def test_no_call_on_get(self):
     """ test that verify_honeypot_value is not called when request.method == GET """
     request = _get_GET_request()
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp, None)
예제 #24
0
파일: utils.py 프로젝트: prmtl/wolnelektury
    def __call__(self, request, *args, **kwargs):
        """A view displaying a form, or JSON if request is AJAX."""
        obj = self.get_object(request, *args, **kwargs)
        form_args, form_kwargs = self.form_args(request, obj)
        if self.form_prefix:
            form_kwargs['prefix'] = self.form_prefix

        if request.method == "POST":
            if self.honeypot:
                response = verify_honeypot_value(request, None)
                if response:
                    return response

            # do I need to be logged in?
            if self.POST_login and not request.user.is_authenticated():
                return require_login(request)

            form_kwargs['data'] = request.POST
            form = self.form_class(*form_args, **form_kwargs)
            if form.is_valid():
                add_args = self.success(form, request)
                response_data = {
                    'success': True, 
                    'message': self.success_message,
                    'redirect': request.GET.get('next')
                    }
                if add_args:
                    response_data.update(add_args)
                if not request.is_ajax() and response_data['redirect']:
                    return HttpResponseRedirect(urlquote_plus(
                            response_data['redirect'], safe='/?=&'))
            elif request.is_ajax():
                # Form was sent with errors. Send them back.
                if self.form_prefix:
                    errors = {}
                    for key, value in form.errors.items():
                        errors["%s-%s" % (self.form_prefix, key)] = value
                else:
                    errors = form.errors
                response_data = {'success': False, 'errors': errors}
            else:
                response_data = None
            if request.is_ajax():
                return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))
        else:
            if (self.POST_login and not request.user.is_authenticated()
                    and not request.is_ajax()):
                return require_login(request)

            form = self.form_class(*form_args, **form_kwargs)
            response_data = None

        title = self.title
        if request.is_ajax():
            template = self.template
        else:
            template = self.full_template
            cd = self.context_description(request, obj)
            if cd:
                title += ": " + cd
        if self.placeholdize:
            form = placeholdized(form)
        context = {
                self.formname: form, 
                "title": title,
                "honeypot": self.honeypot,
                "placeholdize": self.placeholdize,
                "submit": self.submit,
                "response_data": response_data,
                "ajax_template": self.template,
                "view_args": args,
                "view_kwargs": kwargs,
            }
        context.update(self.extra_context(request, obj))
        return render_to_response(template, context,
            context_instance=RequestContext(request))
예제 #25
0
 def process_view(self, request, callback, callback_args, callback_kwargs):
     if request.is_ajax():
         return None
     return verify_honeypot_value(request, None)
예제 #26
0
 def test_field_missing(self):
     """ test that verify_honeypot_value succeeds when HONEYPOT_FIELD_NAME is missing from request.POST """
     request = _get_POST_request()
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp.__class__, HttpResponseBadRequest)
예제 #27
0
파일: views.py 프로젝트: Osmose/kuma
 def dispatch(self, request, *args, **kwargs):
     response = verify_honeypot_value(request, None)
     if isinstance(response, HttpResponseBadRequest):
         return response
     return super(SignupView, self).dispatch(request, *args, **kwargs)
예제 #28
0
 def test_field_blank(self):
     """ test that verify_honeypot_value succeeds when HONEYPOT_VALUE is blank """
     request = _get_POST_request()
     request.POST[settings.HONEYPOT_FIELD_NAME] = ""
     resp = verify_honeypot_value(request, None)
     self.assertEquals(resp, None)