Django rest auth email instead of username

I have a django project in which I use Django-rest-auth for authentication. I want to use email with a password to authenticate the user, not the username and password.

I have the following settings in my .py settings, but it did nothing for me:

REST_SESSION_LOGIN = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'EMAIL'
ACCOUNT_EMAIL_VERIFICATION = 'optional'

How can i achieve this?

+4
source share
2 answers

After completing the setup:

#This is required otherwise it asks for email server
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# ACCOUNT_EMAIL_REQUIRED = True
# AUTHENTICATION_METHOD = 'EMAIL'
# ACCOUNT_EMAIL_VERIFICATION = 'optional'

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True   
ACCOUNT_USERNAME_REQUIRED = False

#Following is added to enable registration with email instead of username
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",
)
+8
source

I also use this package, and by calling this configuration, it worked for me:

ACCOUNT_AUTHENTICATION_METHOD = 'email'

, django-allauth, . :

class AuthenticationMethod:
    USERNAME = 'username'
    EMAIL = 'email'
    USERNAME_EMAIL = 'username_email'

- , allauth, "EMAIL" .

,

0

All Articles