Added username validation to the change username form, to avoid database key collision exceptions. Instead give a message to contact the secretariat to resolve the situation.

- Legacy-Id: 15490
This commit is contained in:
Henrik Levkowetz 2018-09-27 12:52:40 +00:00
parent b11afc00bf
commit 3756923f40

View file

@ -256,3 +256,9 @@ class ChangeUsernameForm(forms.Form):
if not self.user.check_password(password):
raise ValidationError('Invalid password')
return password
def clean_username(self):
username = self.cleaned_data['username']
if User.objects.filter(username=username).exists():
raise ValidationError("A login with that username already exists. Please contact the secretariat to get this resolved.")
return username