Add better email verification
This commit is contained in:
@@ -81,6 +81,9 @@ class SubmissionForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, user=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# Stash for `clean()` -- the per-email cap needs to know whether the
|
||||
# incoming submission is OAuth (user.email) or guest (guest_email).
|
||||
self.user = user
|
||||
|
||||
# Filament dropdown shows only operator-curated, currently-loaded rows.
|
||||
self.fields["requested_filament"].queryset = Filament.objects.filter(
|
||||
@@ -118,6 +121,26 @@ class SubmissionForm(forms.ModelForm):
|
||||
|
||||
def clean(self):
|
||||
cleaned = super().clean()
|
||||
|
||||
# Per-email cap (plan.md §6). Run this BEFORE the source-type checks
|
||||
# so a user already at quota doesn't get a misleading "pick a source"
|
||||
# error message; the cap is the real reason their submission failed.
|
||||
owner_email = (
|
||||
self.user.email
|
||||
if (self.user and self.user.is_authenticated)
|
||||
else cleaned.get("guest_email")
|
||||
)
|
||||
if owner_email:
|
||||
active = Submission.active_count_for_email(owner_email)
|
||||
cap = Submission.MAX_ACTIVE_SUBMISSIONS_PER_EMAIL
|
||||
if active >= cap:
|
||||
raise forms.ValidationError(
|
||||
f"You already have {active} active submission(s) -- "
|
||||
f"that's the per-email cap of {cap}. Wait for some to "
|
||||
f"finish printing (or be cleaned up after rejection) "
|
||||
f"before submitting another."
|
||||
)
|
||||
|
||||
source_type = cleaned.get("source_type")
|
||||
stl_file = cleaned.get("stl_file")
|
||||
source_url = cleaned.get("source_url")
|
||||
|
||||
Reference in New Issue
Block a user