2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 14:28:09 +00:00

form now working with basic validation

This commit is contained in:
2025-01-20 21:57:11 +00:00
parent d79ffd8354
commit ba5987b674
4 changed files with 63 additions and 17 deletions

View File

@@ -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():
# <process form cleaned data>
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;"}
) )
# )
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."
)