简体   繁体   中英

django allauth email login - always wrong

If I change my allauth authentication method to email in django settings I always get the following error:

The e-mail address and/or password you specified are not correct.

Even though the email matches the one in the database.

I tried this in a clean django project using the following settings:

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "optional"

I set email verification to optional to eliminate a source for the error but the issue remains regardless of whether or not I confirm the email address.

Had same issue today, my solution was that I was missed the AUTHENTICATION_BACKENDS step when installing allauth.

Ensure you have the following in your settings.py

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend"
)

See http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial for a helpful guide

Had the same issue today and none of the above solutions helped. The issue was coming from a custom login template I used to display input fields.

So either use the default way to render forms or make sure you are using login as a name for your email input field :

<input type="email" name="login" required="">
<input type="password" name="password" required=""> 

I previously was using email which was throwing an error

Login doesn't exists

I know this is an old post but in case anyone comes across it. These are all the setting in settings.py i added in order to enable email login

ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True

I faced the same problem. My arse was on fire because of deadline, hence I figured out a way around. Thought of sharing. I took the user instance by using the filter and then populated the POST by copying the data from original request.

self.user = User.objects.get(email=request.POST['email'])

then

self.request.POST = self.request.DATA.copy()

I was using REST Request objects, hence the DATA . You can create another mutable POST object using some method.Note that original POST is immutable and you can't add anything into it. And then finally

self.request.POST['login'] = self.user.username

and then calling the form_valid of LoginView . Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM