fix: harden tubco login matching
Some checks failed
CI / python-validation (push) Has been cancelled
CI / docker-release-gate (push) Has been cancelled
i18n / compile-translations (push) Has been cancelled

This commit is contained in:
Md Bayazid Bostame
2026-04-08 13:52:00 +02:00
parent b60d9eaeb7
commit 5b1fd6dc14
2 changed files with 29 additions and 1 deletions

View File

@@ -135,6 +135,8 @@ class AppLoginForm(forms.Form):
auth_username = login_value
user_model = get_user_model()
matched_user = user_model.objects.filter(email__iexact=login_value).first()
if matched_user is None:
matched_user = user_model.objects.filter(username__iexact=login_value).first()
if matched_user:
auth_username = matched_user.username
self.user_cache = authenticate(self.request, username=auth_username, password=password)
@@ -494,7 +496,7 @@ class UserManagementCreateForm(forms.Form):
def clean_username(self):
username = (self.cleaned_data.get('username') or '').strip()
user_model = get_user_model()
if user_model.objects.filter(username=username).exists():
if user_model.objects.filter(username__iexact=username).exists():
raise forms.ValidationError(_('Dieser Benutzername ist bereits vergeben.'))
return username