mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 23:20:51 +00:00
Add ToC
This commit is contained in:
40
thirdpart/termsandconditions/pipeline.py
Normal file
40
thirdpart/termsandconditions/pipeline.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""This file contains functions used as part of a user creation pipeline, such as django-social-auth."""
|
||||
|
||||
# pylint: disable=W0613
|
||||
|
||||
try:
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
except ImportError:
|
||||
from urlparse import urlparse, urlunparse
|
||||
from .models import TermsAndConditions
|
||||
from django.http import HttpResponseRedirect, QueryDict
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
import logging
|
||||
|
||||
ACCEPT_TERMS_PATH = getattr(settings, 'ACCEPT_TERMS_PATH', '/terms/accept/')
|
||||
TERMS_RETURNTO_PARAM = getattr(settings, 'TERMS_RETURNTO_PARAM', 'returnTo')
|
||||
|
||||
LOGGER = logging.getLogger(name='termsandconditions')
|
||||
|
||||
|
||||
def user_accept_terms(backend, user, uid, social_user=None, *args, **kwargs):
|
||||
"""Check if the user has accepted the terms and conditions after creation."""
|
||||
|
||||
LOGGER.debug('user_accept_terms')
|
||||
|
||||
if not TermsAndConditions.agreed_to_latest(user):
|
||||
return redirect_to_terms_accept('/')
|
||||
else:
|
||||
return {'social_user': social_user, 'user': user}
|
||||
|
||||
|
||||
def redirect_to_terms_accept(current_path='/', slug='default'):
|
||||
"""Redirect the user to the terms and conditions accept page."""
|
||||
redirect_url_parts = list(urlparse(ACCEPT_TERMS_PATH))
|
||||
if slug != 'default':
|
||||
redirect_url_parts[2] += slug
|
||||
querystring = QueryDict(redirect_url_parts[4], mutable=True)
|
||||
querystring[TERMS_RETURNTO_PARAM] = current_path
|
||||
redirect_url_parts[4] = querystring.urlencode(safe='/')
|
||||
return HttpResponseRedirect(urlunparse(redirect_url_parts))
|
Reference in New Issue
Block a user