Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the method through ajax verify what the user input whether right #35

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ Documentation
+++++++++++++

Read the `documentation online <http://readthedocs.org/docs/django-simple-captcha>`_.

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.

1 change: 1 addition & 0 deletions captcha/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
url(r'image/(?P<key>\w+)/$', 'captcha_image', name='captcha-image'),
url(r'audio/(?P<key>\w+)/$', 'captcha_audio', name='captcha-audio'),
url(r'refresh/$', 'captcha_refresh', name='captcha-refresh'),
url(r'verify/$','captcha_verify',name='captcha-verify'),
)
18 changes: 18 additions & 0 deletions captcha/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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