17

我有一个 django 项目,我在其中使用 Django-rest-auth 进行身份验证。我想使用带密码的电子邮件来验证用户身份,而不是用户名+密码。

我的 settings.py 中有以下设置,但它没有为我做任何事情:

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

我怎样才能实现它?

4

2 回答 2

30

以下设置有效:

#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",
)
于 2016-04-19T07:46:24.110 回答
0

我也在使用这个包,通过调用这个配置它对我有用:

ACCOUNT_AUTHENTICATION_METHOD = 'email'

小心这个配置,这个配置属于django-allauth,看这个:

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

上面的类是 中的设置allauth,所以你应该用小写写 'EMAIL'。

于 2016-04-19T04:47:58.057 回答