Files
www/membership/members/forms.py
T
2026-10-23 12:02:50 -04:00

27 lines
1.2 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django import forms
from django.contrib.auth.password_validation import validate_password
class RegistrationForm(forms.Form):
uid = forms.RegexField(regex=r"^[a-z][a-z0-9._-]{2,47}$", max_length=48, label="Username", help_text="3–48 lowercase letters, numbers, dots, underscores or hyphens. Start with a letter.")
email = forms.EmailField(max_length=254)
def clean_email(self):
return self.cleaned_data["email"].strip().casefold()
class PasswordForm(forms.Form):
password = forms.CharField(max_length=1024, widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}), label="Password", help_text="At least 12 characters. Stored only in OpenLDAP, never on this website.")
confirm_password = forms.CharField(max_length=1024, widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}), label="Confirm password")
def clean_password(self):
password = self.cleaned_data["password"]
validate_password(password)
return password
def clean(self):
data = super().clean()
if data.get("password") != data.get("confirm_password"):
self.add_error("confirm_password", "Passwords must match.")
return data