From ba5987b67417ef6af563dbe7c8405f4c6182eaee Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 20 Jan 2025 21:57:11 +0000 Subject: form now working with basic validation --- core/views/user_registration.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'core/views/user_registration.py') diff --git a/core/views/user_registration.py b/core/views/user_registration.py index df00ed9..d4ce58e 100644 --- a/core/views/user_registration.py +++ b/core/views/user_registration.py @@ -1,6 +1,7 @@ from django import forms from django.http import HttpResponseRedirect from django.shortcuts import render +from django.core.exceptions import ValidationError """ This is the new individual user login registration, instead of everyone signing @@ -13,7 +14,10 @@ def register(request): form = register_form(request.POST) if form.is_valid(): # - return HttpResponseRedirect("/success/") + un = form.cleaned_data["username"] + pw= form.cleaned_data["password1"] + + return HttpResponseRedirect("/accounts/login/") else: form = register_form(initial={"visible": "True"}) @@ -26,17 +30,31 @@ class register_form(forms.Form): # not a model-form, just a form-form attrs={"size": 35, "placeholder": "e.g. anathema-device", "style": "vertical-align: text-top;"} )) + email = forms.CharField(strip=True, required=True, + label="email", + widget=forms.TextInput( + attrs={"size": 35, "placeholder": "e.g. anathema@potatohut.exp", + "style": "vertical-align: text-top;"} + )) password1 = forms.CharField(strip=True, required=True, - label="Password", + label="Troggle password", widget=forms.TextInput( attrs={"size": 30, "placeholder": "your new login password", "style": "vertical-align: text-top;"} )) password2 = forms.CharField(strip=True, required=True, - label="Re-type your password", + label="Re-type your troggle password", widget=forms.TextInput( attrs={"size": 30, "placeholder": "same as the password above", "style": "vertical-align: text-top;"} ) ) - # ) \ No newline at end of file + def clean(self): + cleaned_data = super().clean() + pw1 = cleaned_data.get("password1") + pw2 = cleaned_data.get("password2") + + if pw1 != pw2: + raise ValidationError( + "Retyped password does not match initial password: please fix this." + ) \ No newline at end of file -- cgit v1.2.3