From: Aleksander Łukasz Date: Thu, 5 Sep 2013 12:08:38 +0000 (+0200) Subject: Non authenticated users aren't allowed to use forum for now X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/87ec81224b9b1d395e78cb283beced5e6a60bb53?ds=inline;hp=--cc Non authenticated users aren't allowed to use forum for now --- 87ec81224b9b1d395e78cb283beced5e6a60bb53 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)