From 072a04487d43be292e3eb9eded5394f2c266d0ba Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 24 Jan 2025 01:10:45 +0000 Subject: [PATCH] stitch together the login sequence better --- core/views/auth.py | 2 +- core/views/other.py | 4 ++-- core/views/signup.py | 6 ++++- templates/{ => errors}/frontpage.html | 2 +- templates/login/index.html | 34 ++++++++++++++++++++------- templates/{ => login}/tasks.html | 0 6 files changed, 34 insertions(+), 14 deletions(-) rename templates/{ => errors}/frontpage.html (93%) rename templates/{ => login}/tasks.html (100%) diff --git a/core/views/auth.py b/core/views/auth.py index 966a100..db17ae3 100644 --- a/core/views/auth.py +++ b/core/views/auth.py @@ -57,7 +57,7 @@ def expologin(request): else: # going to login page when you are already logged in from django.contrib.admin.templatetags import log - return render(request, "tasks.html", {}) + return render(request, "login/tasks.html", {}) # POST username = request.POST["username"] diff --git a/core/views/other.py b/core/views/other.py index f1a7bdf..4019e73 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -104,12 +104,12 @@ def frontpage(request): """never seen in common practice. Logon should redirect here when this is more useful""" if request.user.is_authenticated: - return render(request, "tasks.html") + return render(request, "login/tasks.html") expeditions = Expedition.objects.order_by("-year") logbookentry = LogbookEntry cave = Cave - return render(request, "frontpage.html", locals()) + return render(request, "login/frontpage.html", locals()) @login_required_if_public diff --git a/core/views/signup.py b/core/views/signup.py index 177b2b7..c0360f9 100644 --- a/core/views/signup.py +++ b/core/views/signup.py @@ -3,6 +3,7 @@ import re from pathlib import Path import django.forms as forms +from django.contrib.auth.decorators import login_required from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import redirect, render from django.urls import reverse @@ -19,13 +20,16 @@ from troggle.core.utils import ( ) from troggle.core.views.editor_helpers import HTMLarea -from .auth import login_required_if_public """The new user signup form and expo user management system in 2025. """ @ensure_csrf_cookie +@login_required def signup(request): + if request.user.username in ["expo", "expoadmin"]: + return redirect("/accounts/newregister/") + # /accounts/login/?next=/signup if request.method == "POST": # If the form has been submitted... pageform = ExpoSignupForm(request.POST) # A form bound to the POST data if pageform.is_valid(): diff --git a/templates/frontpage.html b/templates/errors/frontpage.html similarity index 93% rename from templates/frontpage.html rename to templates/errors/frontpage.html index e2ff96b..461bce9 100644 --- a/templates/frontpage.html +++ b/templates/errors/frontpage.html @@ -22,7 +22,7 @@ Here you will find information about the {{expedition.objects.count}} expedition You are not logged-in, so a few of the unpublished cave survey pages will not be visible to you. And of course you will not be able to edit anything.

- +

Nial in Eishohle in 2007. {% endblock content %} diff --git a/templates/login/index.html b/templates/login/index.html index 889149d..62e3d51 100644 --- a/templates/login/index.html +++ b/templates/login/index.html @@ -4,11 +4,16 @@ + +

Troggle user login

@@ -23,7 +28,7 @@ This is because Django is Opinionated and does lots of Invisible Defaults

{{message }}

{% endif %} -

Troggle ordinary user login - no access to Django control panel

+

Troggle login - no administrative access

(This is using template login/index.html)

@@ -31,14 +36,14 @@ This is because Django is Opinionated and does lots of Invisible Defaults
{% if invalid %}

The username and password you provided don't match. Please try again.

-

Have you forgotten your password?
- Or perhaps your username?

- -

Neither of those links work yet, by the way, I'm only trying to *appear* helpful. - +

+ Have you forgotten your username?
+ Or have you forgotten your password?
+

+
{% endif %} -
+
{% csrf_token %} @@ -47,8 +52,19 @@ This is because Django is Opinionated and does lots of Invisible Defaults

-

+ + + +

+ Do you want to register for a personal login having been on expo before? +

+ or +

+ Is this your first time here and do you want to register as a new user? +



{{form}} diff --git a/templates/tasks.html b/templates/login/tasks.html similarity index 100% rename from templates/tasks.html rename to templates/login/tasks.html