簡體   English   中英

使用django allauth的自定義用戶

[英]Custom users with django allauth

我正在嘗試使用具有django-allauth / social auth的自定義用戶在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",
)

SOCIALACCOUNT_PROVIDERS = \
    {'facebook':
       {'SCOPE': ['email', 'user_likes', 'user_status', 'user_about_me', 'basic_info', 'read_stream'],
        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'METHOD': 'oauth2',
        'LOCALE_FUNC': 'path.to.callable',
        'VERIFIED_EMAIL': False}}


LOGIN_REDIRECT_URL = '/results/' 
AUTH_USER_MODEL = 'users.User'

在項目文件夾內的用戶文件夾中,我有adapter.py:

from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter

class MyAccountAdapter(DefaultAccountAdapter):

def get_login_redirect_url(self, request):
    path = "/results/{username}/"
    return path.format(username=request.user.username)

在models.py中:

from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
    user_data = models.TextField(null=True)

當我嘗試使用facebook登錄時,我被重定向到facebook,但返回到站點,卻收到以下錯誤消息

Django version 1.6.2
Exception Type: DoesNotExist
User matching query does not exist.

並在控制台中

"GET /results/facebook/login/? HTTP/1.1" 302 0
"GET /results/facebook/login/callback/XXX HTTP/1.1" 500

知道我在做什么錯嗎?

我認為您可能正在通過電子郵件搜索用戶名,反之亦然。 嘗試指定以下內容:

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM