问题
I am trying to use a custom user with django-allauth/social auth In settings.py, I have
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'
In a folder users within the project folder, I have 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)
In models.py:
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
user_data = models.TextField(null=True)
When I try to log in with facebook, I get redirected to facebook but returning to the site, I get the following error message
Django version 1.6.2
Exception Type: DoesNotExist
User matching query does not exist.
and in the console
"GET /results/facebook/login/? HTTP/1.1" 302 0
"GET /results/facebook/login/callback/XXX HTTP/1.1" 500
Any idea what I am doing wrong?
回答1:
I think you might be searching for a username with an email or viceversa. Try specifying this:
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
来源:https://stackoverflow.com/questions/24066914/custom-users-with-django-allauth