diff --git a/scipost/forms.py b/scipost/forms.py index 8273339f4df468b302262e7b6f311a026deec94c..ba8274e92c76cd6d68f92a9543551d88c3c8fab7 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -307,7 +307,17 @@ class AuthenticationForm(forms.Form): """ username = self.cleaned_data['username'] password = self.cleaned_data['password'] - return authenticate(username=username, password=password) + user = authenticate(username=username, password=password) + if user: + return user + + try: + _user = User.objects.get(email=username) + return authenticate(username=_user.username, password=password) + except: + # Catch all exceptions. This method should be upgraded in the next Django + # update anyway and not a single exception should propagate to the user, never! + return None def get_redirect_url(self, request): """