diff --git a/README.rst b/README.rst index 8a7ed318..d459c0af 100644 --- a/README.rst +++ b/README.rst @@ -35,3 +35,14 @@ Documentation +++++++++++++ Read the `documentation online `_. + +add the method through ajax verify what the user input whether right +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +how to use: + ajax send messages: + verify_data = $('#id_captcha_1').val(), + key = $('#id_captcha_0').val(), + + if the return result is "true",right,or "false" then not true. + diff --git a/captcha/urls.py b/captcha/urls.py index 7de753f6..d3dfee14 100644 --- a/captcha/urls.py +++ b/captcha/urls.py @@ -7,4 +7,5 @@ url(r'image/(?P\w+)/$', 'captcha_image', name='captcha-image'), url(r'audio/(?P\w+)/$', 'captcha_audio', name='captcha-audio'), url(r'refresh/$', 'captcha_refresh', name='captcha-refresh'), + url(r'verify/$','captcha_verify',name='captcha-verify'), ) diff --git a/captcha/views.py b/captcha/views.py index b24fdfc5..4cb95186 100644 --- a/captcha/views.py +++ b/captcha/views.py @@ -119,3 +119,21 @@ def captcha_refresh(request): return HttpResponse(json.dumps(to_json_responce), content_type='application/json') raise Http404 + +def captcha_verify(request): + """ + Check whether the input is right for ajax verify request + """ + + if request.is_ajax(): + try: + response = request.GET.get('verify_data') + key = request.GET.get('key') + except Exception,e: + traceback.print_stack() + raise Http404 + store = get_object_or_404(CaptchaStore, hashkey=key) + result = 'true' if store.response == response else 'false' + + return HttpResponse(json.dumps([result]), mimetype='application/json') + raise Http404