diff options
Diffstat (limited to 'core/views/auth.py')
-rw-r--r-- | core/views/auth.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/core/views/auth.py b/core/views/auth.py index 19b80a4..a7b2ca1 100644 --- a/core/views/auth.py +++ b/core/views/auth.py @@ -1,8 +1,27 @@ from builtins import str + +from django.conf import settings from django.shortcuts import render -from django.http import Http404, HttpResponseRedirect from django.contrib.auth import authenticate, login, logout from django.contrib.auth import forms as auth_forms +from django.contrib.auth.decorators import login_required + +"""This enforces the login requirement for non-public pages using +the decorator mechanism. +https://www.fullstackpython.com/django-contrib-auth-decorators-login-required-examples.html +""" + +class login_required_if_public(object): + + def __init__(self, f): + if settings.PUBLIC_SITE: + self.f = login_required(f) + else: + self.f = f + + def __call__(self, *args, **kwargs): + return self.f(*args, **kwargs) + # This is copied from CUYC.cuy.website.view.auth # If we want to do the whole online-email thing, we would also need to copy across the code in these |