1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 10:58:33 +00:00
This commit is contained in:
zhengxie
2016-07-15 10:47:32 +08:00
parent 126da528b5
commit 41f9a3950c
24 changed files with 1180 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
"""View Decorators for termsandconditions module"""
try:
from urllib.parse import urlparse, urlunparse
except ImportError:
from urlparse import urlparse, urlunparse
from functools import wraps
from django.http import HttpResponseRedirect, QueryDict
from django.utils.decorators import available_attrs
from .models import TermsAndConditions
from .middleware import ACCEPT_TERMS_PATH
def terms_required(view_func):
"""
This decorator checks to see if the user is logged in, and if so, if they have accepted the site terms.
"""
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
"""Method to wrap the view passed in"""
if not request.user.is_authenticated() or TermsAndConditions.agreed_to_latest(request.user):
return view_func(request, *args, **kwargs)
currentPath = request.path
login_url_parts = list(urlparse(ACCEPT_TERMS_PATH))
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring['returnTo'] = currentPath
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urlunparse(login_url_parts))
return _wrapped_view