Commit c666e0f0 authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos
Browse files

Crreated a custom decorator to support social auth

Created a login-required - like decorator to indicate that the user should
be social active in order to view protected views. Added the decorator in any
place that the login_required exists.
parent 4daaf632
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.utils.translation import ugettext as _
from accounts.models import *
from edumanage.forms import *
from edumanage.models import *
def social_active_required(function):
def wrap(request, *args, **kw):
user=request.user
try:
profile = request.user.get_profile()
if profile.is_social_active == True:
return function(request, *args, **kw)
else:
status = _("User account <strong>%s</strong> is pending activation. Administrators have been notified and will activate this account within the next days. <br>If this account has remained inactive for a long time contact your technical coordinator or GRNET Helpdesk") %user.username
return render_to_response('status.html', {'status': status, 'inactive': True},
context_instance=RequestContext(request))
except UserProfile.DoesNotExist:
form = UserProfileForm()
form.fields['user'] = forms.ModelChoiceField(queryset=User.objects.filter(pk=user.pk), empty_label=None)
nomail = False
if not user.email:
nomail = True
form.fields['email'] = forms.CharField()
else:
form.fields['email'] = forms.CharField(initial = user.email)
form.fields['institution'] = forms.ModelChoiceField(queryset=Institution.objects.all(), empty_label=None)
return render_to_response('registration/select_institution.html', {'form': form, 'nomail': nomail}, context_instance=RequestContext(request))
return wrap
\ No newline at end of file
......@@ -31,12 +31,15 @@ from django.contrib.auth import authenticate, login
from registration.models import RegistrationProfile
from django.core.cache import cache
from edumanage.decorators import social_active_required
@never_cache
def index(request):
return render_to_response('front/index.html', context_instance=RequestContext(request))
@login_required
@social_active_required
@never_cache
def manage(request):
services_list = []
......@@ -62,6 +65,7 @@ def manage(request):
context_instance=RequestContext(request, base_response(request)))
@login_required
@social_active_required
@never_cache
def institutions(request):
user = request.user
......@@ -85,6 +89,7 @@ def institutions(request):
@login_required
@social_active_required
@never_cache
def add_institution_details(request, institution_pk):
user = request.user
......@@ -139,6 +144,7 @@ def add_institution_details(request, institution_pk):
@login_required
@social_active_required
@never_cache
def services(request, service_pk):
user = request.user
......@@ -185,6 +191,7 @@ def services(request, service_pk):
@login_required
@social_active_required
@never_cache
def add_services(request, service_pk):
user = request.user
......@@ -269,6 +276,7 @@ def add_services(request, service_pk):
@login_required
@social_active_required
@never_cache
def del_service(request):
if request.method == 'GET':
......@@ -297,6 +305,7 @@ def del_service(request):
@login_required
@social_active_required
@never_cache
def servers(request, server_pk):
user = request.user
......@@ -322,6 +331,7 @@ def servers(request, server_pk):
@login_required
@social_active_required
@never_cache
def add_server(request, server_pk):
user = request.user
......@@ -376,6 +386,7 @@ def add_server(request, server_pk):
@login_required
@social_active_required
@never_cache
def del_server(request):
if request.method == 'GET':
......@@ -404,6 +415,7 @@ def del_server(request):
@login_required
@social_active_required
@never_cache
def realms(request):
user = request.user
......@@ -422,6 +434,7 @@ def realms(request):
@login_required
@social_active_required
@never_cache
def add_realm(request, realm_pk):
user = request.user
......@@ -482,6 +495,7 @@ def add_realm(request, realm_pk):
@login_required
@social_active_required
@never_cache
def del_realm(request):
if request.method == 'GET':
......@@ -510,6 +524,7 @@ def del_realm(request):
@login_required
@social_active_required
@never_cache
def contacts(request):
user = request.user
......@@ -533,6 +548,7 @@ def contacts(request):
@login_required
@social_active_required
@never_cache
def add_contact(request, contact_pk):
user = request.user
......@@ -589,6 +605,7 @@ def add_contact(request, contact_pk):
@login_required
@social_active_required
@never_cache
def del_contact(request):
if request.method == 'GET':
......@@ -625,6 +642,7 @@ def del_contact(request):
@login_required
@social_active_required
@never_cache
def instrealmmon(request):
user = request.user
......@@ -646,6 +664,7 @@ def instrealmmon(request):
context_instance=RequestContext(request, base_response(request)))
@login_required
@social_active_required
@never_cache
def add_instrealmmon(request, instrealmmon_pk):
user = request.user
......@@ -696,6 +715,7 @@ def add_instrealmmon(request, instrealmmon_pk):
context_instance=RequestContext(request, base_response(request)))
@login_required
@social_active_required
@never_cache
def del_instrealmmon(request):
if request.method == 'GET':
......@@ -719,6 +739,7 @@ def del_instrealmmon(request):
return HttpResponse(json.dumps(resp), mimetype='application/json')
@login_required
@social_active_required
@never_cache
def add_monlocauthpar(request, instrealmmon_pk, monlocauthpar_pk):
user = request.user
......@@ -779,6 +800,7 @@ def add_monlocauthpar(request, instrealmmon_pk, monlocauthpar_pk):
context_instance=RequestContext(request, base_response(request)))
@login_required
@social_active_required
@never_cache
def del_monlocauthpar(request):
if request.method == 'GET':
......@@ -802,6 +824,7 @@ def del_monlocauthpar(request):
return HttpResponse(json.dumps(resp), mimetype='application/json')
@login_required
@social_active_required
@never_cache
def adduser(request):
user = request.user
......@@ -833,6 +856,7 @@ def adduser(request):
@login_required
@social_active_required
def base_response(request):
user = request.user
inst = []
......@@ -878,6 +902,7 @@ def base_response(request):
@login_required
@social_active_required
@never_cache
def get_service_points(request):
if request.method == "GET":
......@@ -1038,9 +1063,10 @@ def user_login(request):
context_instance=RequestContext(request))
@never_cache
@login_required
def check_user_inst(request):
user = request.user
u = request.user.__dict__
s = request.session.keys()
raise Exception
try:
profile = user.get_profile()
inst = profile.institution
......@@ -1494,3 +1520,6 @@ def lookupShibAttr(attrmap, requestMeta):
return requestMeta[attr]
return ''
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment