mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
🐛 A new user can't take an existing alias as username
This commit is contained in:
@ -5,7 +5,7 @@ from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note.models import NoteSpecial
|
||||
from note.models import NoteSpecial, Alias
|
||||
from note_kfet.inputs import AmountInput
|
||||
|
||||
|
||||
@ -22,6 +22,12 @@ class SignUpForm(UserCreationForm):
|
||||
self.fields['email'].required = True
|
||||
self.fields['email'].help_text = _("This address must be valid.")
|
||||
|
||||
def clean_username(self):
|
||||
value = self.cleaned_data["username"]
|
||||
if Alias.objects.filter(normalized_name=Alias.normalize(value)).exists():
|
||||
self.add_error("username", _("An alias with a similar name already exists."))
|
||||
return value
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name', 'username', 'email', )
|
||||
|
Reference in New Issue
Block a user