summaryrefslogtreecommitdiff
path: root/gnowsys-ndf/gnowsys_ndf/ndf
diff options
context:
space:
mode:
Diffstat (limited to 'gnowsys-ndf/gnowsys_ndf/ndf')
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Captcha.html73
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/login.html19
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/urls/__init__.py4
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/urls/captcha.py12
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/Captcha.py36
5 files changed, 139 insertions, 5 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Captcha.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Captcha.html
new file mode 100644
index 00000000..971e9c6d
--- /dev/null
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Captcha.html
@@ -0,0 +1,73 @@
+{% load i18n %}
+{% load ndf_tags %}
+
+
+<div class = "row">
+ <div class = "medium-3 column" id = "captcha-content" >
+ <!-- Area to append captcha -->
+ </div>
+
+ <br>
+
+ <div class = "medium-4 column" ends>
+ <label class='fi-refresh js-captcha-refresh'> </button>
+ </div>
+
+</div>
+<div class = "invalid-captcha">
+
+</div>
+<script type="text/javascript">
+
+ var formData = [];
+ $('form').submit(function(event){
+ event.preventDefault();
+
+ $('form').find("input[name]").each(function (index, node) {
+ formData.push(String(node.name) + ":"+ String(node.value));
+ });
+
+ $.ajax({
+ url: "{% url 'captcha_validate' %}",
+ type:"POST",
+ data:{
+ formData,
+ csrfmiddlewaretoken: '{{ csrf_token }}'},
+ success:function(data)
+ { if (data == 'True')
+ { //Diconnect the on Submit action from form
+ $('form').off("submit")
+ //Trigger the submit action manually
+ $('form').submit()
+ }
+ else
+ { $('.invalid-captcha').empty();
+ $('.invalid-captcha').append("<labe style = 'color:red;'> invalid captcha Try Again !! </label>")
+ }
+ }
+ });
+ });
+
+ $(document).ready(function(){
+ get_new_captcha();
+ });
+
+
+ function get_new_captcha(){
+ $.ajax({
+ url:"{% url 'new_captcha' %}",
+ type:"GET",
+ success:function(data)
+ {
+ $('#captcha-content').empty()
+ $('#captcha-content').append(data)
+ }
+ });
+ }
+
+ $('.js-captcha-refresh').click(function(){
+ get_new_captcha();
+ });
+
+
+</script> \ No newline at end of file
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/login.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/login.html
index a07822c1..ac185932 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/login.html
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/login.html
@@ -1,6 +1,6 @@
{% extends "registration/registration_base.html" %}
{% load i18n %}
-
+{% load ndf_tags %}
{% block title %}{% trans "Login" %}{% endblock %}
{% block style %}
@@ -19,7 +19,7 @@
{% block body_content %}
{% url 'auth_password_reset' as auth_pwd_reset_url %}
{% url 'registration_register' as register_url %}
-
+
<div class="row" style="margin: 1.2rem 0;">
<div class="small-8 medium-8 large-8 small-centered medium-centered large-centered columns">
<div class="row">
@@ -70,7 +70,9 @@
{{ form.password }}
</div>
</div>
-
+ <div class = "captcha-feild">
+ {% include "ndf/Captcha.html" %}
+ </div>
<!-- Login button -->
<div class="row">
<div class="small-2 large-2 small-offset-3 large-offset-3 columns end">
@@ -94,6 +96,7 @@
{% endif %}
<input type="hidden" name="next" value="{{ next }}" />
</form>
+
</div>
</div>
{% endblock %}
@@ -111,5 +114,15 @@
$(this).attr("required", "");
$(this).after("<small class='error'>Please fill valid "+this.name+"</small>");
});
+
+ //Code to refresh the Captcha
+ $('.js-captcha-refresh').click(function(){
+ $form = $(this).parents('form');
+
+ $.getJSON($(this).data('url'), {}, function(json) {
+ // This should update your captcha image src and captcha hidden input
+ });
+ return false;
+ });
{% endblock %} \ No newline at end of file
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/__init__.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/__init__.py
index 0fad1de1..ffb3db7e 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/__init__.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/__init__.py
@@ -33,12 +33,12 @@ urlpatterns = patterns('',
# (r'^new/$', 'gnowsys_ndf.mobwrite.views.new'),
# (r'^mobwrite/', 'gnowsys_ndf.mobwrite.views.mobwrite'),
# --end of mobwrite
-
(r'^admin/', include(admin.site.urls)),
# (r'^$', HomeRedirectView.as_view()),
url(r'^$', homepage, {"group_id": "home"}, name="homepage"),
url(r'^welcome/?', landing_page, name="landing_page"),
-
+ url(r'^captcha/', include('captcha.urls')),
+ (r'^', include('gnowsys_ndf.ndf.urls.captcha')),
# all main apps
(r'^(?P<group_id>[^/]+)/file', include('gnowsys_ndf.ndf.urls.file')),
(r'^(?P<group_id>[^/]+)/image', include('gnowsys_ndf.ndf.urls.image')),
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/captcha.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/captcha.py
new file mode 100644
index 00000000..1434e187
--- /dev/null
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/captcha.py
@@ -0,0 +1,12 @@
+from django.conf.urls import patterns, url
+
+from django.views.generic import TemplateView
+
+from gnowsys_ndf.ndf.views import Captcha
+
+urlpatterns = patterns('gnowsys_ndf.ndf.views.Captcha',
+ url(r'^validate_captcha/', 'captcha_validate', name='captcha_validate'),
+ url(r'^new_captcha/', 'new_captcha', name='new_captcha')
+ )
+
+
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/Captcha.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/Captcha.py
new file mode 100644
index 00000000..74623f43
--- /dev/null
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/Captcha.py
@@ -0,0 +1,36 @@
+from django.views.generic.edit import CreateView
+import json
+from django import forms
+from captcha.fields import CaptchaField
+from django.http import HttpResponse
+from django.http import StreamingHttpResponse
+
+class CaptchaTestForm(forms.Form):
+ ''' class to instantiate CaptchaField() '''
+ captcha = CaptchaField()
+
+def captcha_validate(request):
+ valid = ""
+ data = request.POST.getlist('formData[]','')
+ data = convert_list_dict(data)
+ form = CaptchaTestForm(data)
+ if form.is_valid():
+ valid = True
+ else:
+ valid = False
+ return HttpResponse(valid)
+
+def new_captcha(request):
+ ''' method to return form'''
+ form = CaptchaTestForm()
+ return StreamingHttpResponse(str(form))
+
+
+def convert_list_dict(data):
+ data_dict = {}
+ for i in data:
+ new_data = i.split(':')
+ data_dict.update({new_data[0]:str(new_data[1])})
+ return data_dict
+
+