summaryrefslogtreecommitdiff
path: root/gnowsys-ndf
diff options
context:
space:
mode:
authormakfire <mukeshpandey15@hotmail.com>2015-06-22 12:02:22 +0530
committermakfire <mukeshpandey15@hotmail.com>2015-06-22 12:02:22 +0530
commit615535de2be2bcb1864ee9bfd58804abf7e396fb (patch)
treeb76a5f91c06b18195ea4ec4ea26fec352e327f17 /gnowsys-ndf
parentede6bf410502473a348cf0b0e295fc5bde8a87b9 (diff)
downloadgnowsys-615535de2be2bcb1864ee9bfd58804abf7e396fb.tar.gz
captcha implemeted
Diffstat (limited to 'gnowsys-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
-rw-r--r--gnowsys-ndf/gnowsys_ndf/settings.py6
6 files changed, 144 insertions, 6 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 0000000..971e9c6
--- /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 a07822c..ac18593 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 0fad1de..ffb3db7 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 0000000..1434e18
--- /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 0000000..74623f4
--- /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
+
+
diff --git a/gnowsys-ndf/gnowsys_ndf/settings.py b/gnowsys-ndf/gnowsys_ndf/settings.py
index 4c4c547..c939518 100644
--- a/gnowsys-ndf/gnowsys_ndf/settings.py
+++ b/gnowsys-ndf/gnowsys_ndf/settings.py
@@ -402,6 +402,7 @@ INSTALLED_APPS = (
'djangoratings',
'notification',
'pagination',
+ 'captcha',
# 'gnowsys_ndf.mobwrite', #textb
# 'south', #textb
# 'django_extensions', #textb
@@ -529,7 +530,6 @@ GSTUDIO_SITE_LANDING_PAGE = "udashboard" # possible values are 'home' and 'udas
GSTUDIO_SITE_HOME_PAGE = None # it is url rendered on template. e.g: "/welcome". Default is: "/home"
GSTUDIO_SITE_NAME = "metaStudio" # holds the name of site. e.g: "NROER, "tiss" etc. (Override it in local_settings)
# GSTUDIO_SITE_EDITOR = "orgitdown" #possible values are 'aloha'and 'orgitdown'
-
# Visibility for 'Create Group'
CREATE_GROUP_VISIBILITY = True
@@ -666,3 +666,7 @@ CACHES = {
WETUBE_USERNAME = "glab"
WETUBE_PASSWORD = "gl@b$@)we!ube"
+#Captcha settings
+CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'
+CAPTCHA_NOISE_FUNCTIONS = ('captcha.helpers.noise_arcs','captcha.helpers.noise_null')
+