diff options
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Captcha.html | 73 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/login.html | 19 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/__init__.py | 4 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/captcha.py | 12 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/Captcha.py | 36 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/group.py | 103 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/settings.py | 6 | ||||
-rw-r--r-- | requirements.txt | 3 |
8 files changed, 166 insertions, 90 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 + + diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py index bc5a8c68..c2297b6e 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py @@ -31,10 +31,10 @@ from gnowsys_ndf.ndf.org2any import org2html # ###################################################################################################################################### -gst_group = node_collection.one({"_type": "GSystemType", 'name': u"Group"}) +group_gst = node_collection.one({'_type': 'GSystemType', 'name': u'Group'}) +gst_group = group_gst app = gst_group -group_gst = node_collection.one({'_type': 'GSystemType', 'name': u'Group'}) moderating_group_gst = node_collection.one({'_type': 'GSystemType', 'name': u'ModeratingGroup'}) file_gst = node_collection.one({'_type': 'GSystemType', 'name': 'File'}) @@ -65,6 +65,7 @@ class CreateGroup(object): - False: If group doesn't exists. ''' + # explicitely using "find_one" query group = node_collection.find_one({'_type': 'Group', 'name': unicode(arg_group_name)}) if group: @@ -280,13 +281,14 @@ class CreateGroup(object): return group_obj.group_type else: - return False + return False # --- END --- get_group_type() ------ def get_all_subgroups_obj_list(self, group_id): ''' - Returns mongokit (find) cursor of sub-group documents. + Returns mongokit (find) cursor of sub-group documents (only immediate first level) / + which are in the post node of argument group_id else returns False. - Takes group_id as compulsory and only argument. ''' @@ -570,6 +572,7 @@ class CreateModeratedGroup(CreateSubGroup): # pg: parent group pg_name = parent_group_object.name pg_moderation_level = parent_group_object.moderation_level + # print pg_moderation_level, "===", pg_name # possible/next mod group name: # sg: sub group @@ -601,16 +604,27 @@ class CreateModeratedGroup(CreateSubGroup): pg_moderation_level += 1 try: - sg_altnames = self.altnames[sg_member_of][pg_moderation_level-1] \ + result = self.get_top_group_of_hierarchy(parent_group_object._id) + altnames_dict_index = -1 + if result: + top_group_obj = result[1] + top_group_moderation_level = top_group_obj.moderation_level + pg_name = top_group_obj.name + altnames_dict_index = top_group_moderation_level - pg_moderation_level + sg_altnames = self.altnames[sg_member_of][altnames_dict_index] \ + u" of " + pg_name + # print "=== in try", sg_altnames except Exception, e: + # print e sg_altnames = sg_name + # print "=== in Exception", sg_altnames # create new sub-group and append it to parent group: sub_group_result_tuple = self.create_subgroup(parent_group_id, sg_name, \ sg_member_of, moderation_level=(pg_moderation_level-1), \ altnames=sg_altnames) + # print "\n=== sub_group_result_tuple", sub_group_result_tuple return sub_group_result_tuple @@ -832,7 +846,7 @@ class CreateModeratedGroup(CreateSubGroup): # w.r.t. altnames dict (defined at class level variable) try: sg_altnames = self.altnames['ModeratingGroup'][index-1] \ - + u" of " + pg_name + + u" of " + top_group_name except Exception, e: # if not found in altnames dict (defined at class level variable) sg_altnames = each_sg.name @@ -1513,70 +1527,6 @@ def group_dashboard(request, group_id=None): # context_instance=RequestContext(request) # ) - -# class EditGroup(View): -# """ -# Class to handle create/edit group requests. -# """ - -# @method_decorator(login_required) -# @method_decorator(get_execution_time) -# def get(self, request, group_id): -# """ -# Catering GET request of rendering group create/edit form. -# """ - -# group_obj = get_group_name_id(group_id, get_obj=True) - -# if group_obj.status == u"DRAFT": -# group_obj, ver = get_page(request, group_obj) -# group_obj.get_neighbourhood(group_obj.member_of) - -# available_nodes = node_collection.find({'_type': u'Group','_id': {'$nin': [group_obj._id]}}, -# {'name': 1, '_id': 0}) -# nodes_list = [str(g_obj.name.strip().lower()) for g_obj in available_nodes] -# # print nodes_list - -# # if in the case we can replace "ndf/create_group.html" with "ndf/edit_group.html" -# return render_to_response("ndf/create_group.html", -# { -# 'node': group_obj, -# 'title': 'Group', # 'appId':app._id, -# 'groupid': group_id, 'group_id': group_id, -# 'nodes_list': nodes_list, -# # 'is_auth_node':is_auth_node -# }, -# context_instance=RequestContext(request) -# ) - -# @method_decorator(login_required) -# @method_decorator(get_execution_time) -# def post(self, request, group_id): -# ''' -# To handle post request of group form. -# To save edited or newly-created group's data. -# ''' -# group_obj = get_group_name_id(group_id, get_obj=True) - -# is_node_changed = get_node_common_fields(request, group_obj, group_id, gst_group) -# # print "=== ", is_node_changed - -# group_obj.group_type = unicode(request.POST.get("group_type", "")) -# group_obj.agency_type = unicode(request.POST.get("agency_type", "")) -# edit_policy = unicode(request.POST.get("edit_policy", "")) - -# is_node_changed = True - -# group_obj.status = u"PUBLISHED" - -# group_obj.save(is_changed=is_node_changed) - -# group_obj.get_neighbourhood(group_obj.member_of) - -# return HttpResponseRedirect(reverse('groupchange', kwargs={'group_id':group_obj._id})) - -# # ===END of class EditGroup() === - @login_required @get_execution_time @@ -1723,24 +1673,11 @@ def switch_group(request,group_id,node_id): @login_required @get_execution_time def publish_group(request,group_id,node): - # ins_objectid = ObjectId() - # if ins_objectid.is_valid(group_id) is False : - # group_ins = node_collection.find_one({'_type': "Group","name": group_id}) - # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) - # if group_ins: - # group_id = str(group_ins._id) - # else: - # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) - # if auth : - # group_id = str(auth._id) - # else : - # pass group_obj = get_group_name_id(group_id, get_obj=True) profile_pic_image = None if group_obj: - # group_obj=node_collection.one({'_id':ObjectId(group_id)}) group_id = group_obj._id # getting the profile pic File object diff --git a/gnowsys-ndf/gnowsys_ndf/settings.py b/gnowsys-ndf/gnowsys_ndf/settings.py index 2a804819..083c469e 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 @@ -669,3 +669,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') + diff --git a/requirements.txt b/requirements.txt index 6b97717e..a7314f33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,4 +21,5 @@ numpy python-memcached django-memcache-admin pandora-client -pymongo==2.8
\ No newline at end of file +pymongo==2.8 +django-simple-captcha |