Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django rest auth email instead of username

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

I have following settings in my settings.py but it didn't do anything 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 it?

like image 417
Thinker Avatar asked Apr 18 '16 15:04

Thinker


1 Answers

Following setting worked:

#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",
)
like image 159
Thinker Avatar answered Oct 26 '22 18:10

Thinker