Opened 6 years ago

Closed 6 years ago

#30465 closed Bug (invalid)

Authenticate: "An error occurred while connecting."

Reported by: Buky Owned by: nobody
Component: contrib.sessions Version: 2.2
Severity: Normal Keywords: authenticate
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (1)

comment:1 by Claude Paroz, 6 years ago

Resolution: invalid
Status: newclosed

I would suggest to get support first through TicketClosingReasons/UseSupportChannels. If you can show that Django is at fault, then reopen the ticket with more details, especially the error traceback.

Note: See TracTickets for help on using tickets.
Back to Top