fix: 🙏 enforce lowercase usernames for integrity

This commit is contained in:
m5ka 2024-03-25 17:18:49 +00:00
parent b50665a62c
commit 58af1acea7

View file

@ -62,7 +62,12 @@ class SignupView(FormView):
form_class = UserForm form_class = UserForm
def form_valid(self, form): def form_valid(self, form):
form.save() form.instance.username = form.instance.username.lower()
try:
form.save()
except IntegrityError:
messages.error(self.request, _("sorry! someone else got to that username first."))
return self.form_invalid(form)
messages.success(self.request, _("that's it! just log in, and you're ready to go.")) messages.success(self.request, _("that's it! just log in, and you're ready to go."))
return redirect("login") return redirect("login")