如何将`app_settings`的`AuthenticationMethod`设置为`username_email`?

问题描述 投票:0回答:1

在我的项目中,我使用allauth,并在我的自定义LoginSerializer的validate方法中:

    if 'allauth' in settings.INSTALLED_APPS:
        from allauth.account import app_settings

        # Authentication through email
        if app_settings.AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.EMAIL:
            user = self._validate_email(email, password)

        # Authentication through username
        if app_settings.AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME:
            user = self._validate_username(username, password)

你看到有app_settings.AuthenticationMethod.EMAILapp_settings.AuthenticationMethod.USERNAME类型。

我阅读了我发现的源代码:

enter image description here

还有另一种类型USERNAME_EMAIL

class AppSettings(object):

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

我在哪里设置allauth使用AuthenticationMethod.USERNAME_EMAIL?

python django django-allauth
1个回答
0
投票

在你的ACCOUNT_AUTHENTICATION_METHOD中配置settings.py它会起作用:

ACCOUNT_AUTHENTICATION_METHOD = 'username_email'

请小心,不要设置AUTHENTICATION_METHOD

你可以在official document找到更多细节。

© www.soinside.com 2019 - 2024. All rights reserved.