﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30465	"Authenticate: ""An error occurred while connecting."""	Buky	nobody	"A strange error appears in Django 2.2 (it's was working in the previous version) when I write a process to authenticate user with email. 


{{{
class LoginForm(forms.Form):
    login = forms.CharField()
    password = forms.CharField()


    def clean(self):
        user = User.objects.filter(
                Q(username__iexact=self.cleaned_data[""login""]) |
                Q(email__iexact=self.cleaned_data[""login""])
            ).first()

         if user:
             if authenticate(username=user.username, password=self.cleaned_data[""password""]) is not None:
                 return self.cleaned_data
             else:
                 self.add_error('login', ""This user is inactive."")
         else:
             self.add_error('login', ""This user does not exist."")
         return self.cleaned_data
}}}

The authentication system work when username is given and correct error is returned when email exist but the password is wrong. But when the credentials are valid, an error is raised in form by Django.

The little work around I found is to replace the mail submitted in the form by the username collect by the query before return the cleaned data:
{{{
if authenticate(username=user.username, password=self.cleaned_data[""password""]) is not None:
    self.cleaned_data['login'] = user.username
    return self.cleaned_data
}}}

I'm pretty sur Django doesn't have this error in 2.1 when I write this code, I had validated that it was working.
Sincerely."	Bug	closed	contrib.sessions	2.2	Normal	invalid	authenticate		Unreviewed	0	0	0	0	0	0
