Private forum

This commit is contained in:
nitely 2014-05-20 19:08:55 -03:00
parent 540d04b426
commit f138904ce6
2 changed files with 39 additions and 1 deletions

View File

@ -6,6 +6,8 @@ from django.utils import timezone
from django.contrib.auth import get_user_model
from django.conf import settings
from django.contrib.auth import logout
from django.core.urlresolvers import resolve
from django.contrib.auth.views import redirect_to_login
User = get_user_model()
@ -65,4 +67,37 @@ class ActiveUserMiddleware(object):
return
if not request.user.is_active:
logout(request)
logout(request)
class PrivateForumMiddleware(object):
def process_request(self, request):
if not settings.ST_PRIVATE_FORUM:
return
if request.user.is_authenticated():
return
resolver_match = resolve(request.path)
if resolver_match.app_name != 'spirit':
return
# Namespacing /user/ would be better but breaks current urls namespace.
url_whitelist = ['user-login',
'user-logout',
'user-register',
'resend-activation',
'registration-activation',
'email-change-confirm',
'password-reset',
'password-reset-done',
'password-reset-confirm',
'password-reset-complete']
if resolver_match.url_name in url_whitelist:
return
return redirect_to_login(next=request.get_full_path(),
login_url=settings.LOGIN_URL)

View File

@ -25,6 +25,8 @@ ST_SEARCH_QUERY_MIN_LEN = 3
ST_USER_LAST_SEEN_THRESHOLD_MINUTES = 1
ST_PRIVATE_FORUM = False
# check out http://pythonhosted.org/Markdown/extensions/index.html
ST_MARKDOWN_EXT = (
'nl2br',
@ -92,6 +94,7 @@ MIDDLEWARE_CLASSES = (
'spirit.middleware.LastIPMiddleware',
'spirit.middleware.LastSeenMiddleware',
'spirit.middleware.ActiveUserMiddleware',
'spirit.middleware.PrivateForumMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (