-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathdecorators.py
More file actions
20 lines (15 loc) · 852 Bytes
/
decorators.py
File metadata and controls
20 lines (15 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from django.http import HttpResponseRedirect
def custom_login_required(function):
"""
This decorator checks if user is logged in as well as if user profile is verified by by admin or not ,
And then redirect user accordingly, if required
"""
def wrapper(request,*args, **kwargs):
user = request.user
if not (user.is_authenticated):
return HttpResponseRedirect('/') # case when user is not logged in
elif (not user.profile.verify) and ( user.is_authenticated == True) and (request.path != '/complete_profile/'):
return HttpResponseRedirect('/complete_profile/') # case when user is logged in but haven't completed profile as after completing profile only user will be able to login
else:
return function(request,*args,**kwargs)
return wrapper