#30465: Authenticate: "An error occurred while connecting."
--------------------------------------------+------------------------------
               Reporter:  TheBuky           |          Owner:  nobody
                   Type:  Bug               |         Status:  new
              Component:  contrib.sessions  |        Version:  2.2
               Severity:  Normal            |       Keywords:  authenticate
           Triage Stage:  Unreviewed        |      Has patch:  0
    Needs documentation:  0                 |    Needs tests:  0
Patch needs improvement:  0                 |  Easy pickings:  0
                  UI/UX:  0                 |
--------------------------------------------+------------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30465>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.82229a4541babfc35bee358d26d22d7c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to