From 87ec81224b9b1d395e78cb283beced5e6a60bb53 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 5 Sep 2013 14:08:38 +0200 Subject: [PATCH 1/1] Non authenticated users aren't allowed to use forum for now --- .../templates/catalogue/lesson/lesson_detail.html | 14 +++++++------- edumed/settings.d/40-middleware.py | 1 + edumed/templates/home.html | 2 +- forum/middleware.py | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 forum/middleware.py diff --git a/catalogue/templates/catalogue/lesson/lesson_detail.html b/catalogue/templates/catalogue/lesson/lesson_detail.html index adc5dc3..f08b5b8 100755 --- a/catalogue/templates/catalogue/lesson/lesson_detail.html +++ b/catalogue/templates/catalogue/lesson/lesson_detail.html @@ -113,13 +113,13 @@ -{% if object.forum_topics.all.count %} -

Na forum

- +{% if request.user.is_authenticated and object.forum_topics.all.count %} +

Na forum

+ {% endif %} diff --git a/edumed/settings.d/40-middleware.py b/edumed/settings.d/40-middleware.py index 8a3d2e6..b9c614d 100644 --- a/edumed/settings.d/40-middleware.py +++ b/edumed/settings.d/40-middleware.py @@ -23,4 +23,5 @@ MIDDLEWARE_CLASSES = tuple(x for x in ( 'django.middleware.cache.FetchFromCacheMiddleware', 'fnpdjango.middleware.SetRemoteAddrFromXRealIP', 'pybb.middleware.PybbMiddleware', + 'forum.middleware.ForumMiddleware' ) if x is not None) diff --git a/edumed/templates/home.html b/edumed/templates/home.html index 59a24c6..e7977e8 100755 --- a/edumed/templates/home.html +++ b/edumed/templates/home.html @@ -43,7 +43,7 @@
  • Pobierz wszystkie lekcje w wersji dla ucznia
  • Słowniczek
  • Metody edukacyjne
  • -
  • Forum
  • + {% if request.user.is_authenticated %}
  • Forum
  • {% endif %}
  • Polityka prywatności i ciasteczka
  • diff --git a/forum/middleware.py b/forum/middleware.py new file mode 100644 index 0000000..fb0a605 --- /dev/null +++ b/forum/middleware.py @@ -0,0 +1,14 @@ +from urllib import urlencode + +from django.contrib.auth import REDIRECT_FIELD_NAME +from django.http import HttpResponseRedirect +from django.core.urlresolvers import reverse +from django_cas.views import login as cas_login + + +class ForumMiddleware: + def process_request(self, request): + if request.path.startswith(reverse('pybb:index')) \ + and (not hasattr(request, 'user') or not request.user.is_authenticated()): + params = urlencode({REDIRECT_FIELD_NAME: request.get_full_path()}) + return HttpResponseRedirect(reverse(cas_login) + '?' + params) -- 2.20.1