diff --git a/account/forms.py b/account/forms.py old mode 100644 new mode 100755 index 1558bb8..1acf493 --- a/account/forms.py +++ b/account/forms.py @@ -7,12 +7,26 @@ from django import forms from django.contrib.auth import authenticate from django.utils.translation import ugettext as _ +class UsernameField(forms.CharField): + """ + The username field makes sure that usernames are always entered in lower-case. + If we do not convert the username to lower-case, Django will create more than + one user object in the database. If we then try to login again, the Django auth + subsystem will do an query that looks like this: username__iexact="username". The + result is an error, because iexact returns the objects for "username" and "Username". + """ + + def to_python(self, value): + value = super(UsernameField, self).to_python(value) + value = value.lower() + return value + class LoginForm(forms.Form): - username = forms.CharField(max_length=255) + username = UsernameField(max_length=255) password = forms.CharField(max_length=255, widget=forms.PasswordInput, help_text=_('Cookies must be enabled.')) - + def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') @@ -79,7 +93,7 @@ class PasswordForm(forms.Form): def clean(self): cleaned_data = super(PasswordForm, self).clean() old_password = cleaned_data.get('old_password') - username = self._request.user.username + username = self._request.user.username.lower() user = authenticate(username=username, password=old_password) if not user or not user.is_active: diff --git a/account/locale/de/LC_MESSAGES/django.po b/account/locale/de/LC_MESSAGES/django.po index ba122c0..cb9f6c9 100644 --- a/account/locale/de/LC_MESSAGES/django.po +++ b/account/locale/de/LC_MESSAGES/django.po @@ -206,7 +206,7 @@ msgstr "c-lab-PIN" #: templates/clabpin.html:8 msgid "Change your c-lab PIN to access the c-lab in the basement." -msgstr "PIN ändern für den Zugang um c-lab im Keller." +msgstr "PIN ändern für den Zugang zum c-lab im Keller." #: templates/gastropin.html:5 msgid "Gastro PIN"