From 9b9f6720e079669fd884d83f6b69833e20d03ff7 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 3 May 2021 20:35:35 +0100 Subject: not found now does 404 & moved login --- core/views/auth.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'core/views/auth.py') 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 -- cgit v1.2.3