Reputation: 137
To work with my custom user model(expending AbstractBaseUser) I put some code in my settings.py but It's not working.. I use email and username both as required and Email is used as login method. please anybody help me T.T
python : 3.4 / django : 1.8.7 / django-allauth : 0.24.1
The Error message
Environment:
Request Method: GET
Request URL: http://localhost:8000/accounts/google/login/callback/?state=6p1TrVVLFiJE&code=4/gXZLKhAK7mFc2zYwMQ6Z6m9SpOzXj8UXn6ESxz7gIhg
Django Version: 1.8.7
Python Version: 3.4.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'main']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/allauth/socialaccount/providers/oauth2/views.py" in view
55. return self.dispatch(request, *args, **kwargs)
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/allauth/socialaccount/providers/oauth2/views.py" in dispatch
125. return complete_social_login(request, login)
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/allauth/socialaccount/helpers.py" in complete_social_login
142. return _complete_social_login(request, sociallogin)
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/allauth/socialaccount/helpers.py" in _complete_social_login
158. ret = _process_signup(request, sociallogin)
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/allauth/socialaccount/helpers.py" in _process_signup
23. sociallogin)
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/allauth/socialaccount/adapter.py" in is_auto_signup_allowed
136. if email_address_exists(email):
File "/Users/nuko/.virtualenvs/I_choose_you_pikachu/lib/python3.4/site-packages/allauth/utils.py" in email_address_exists
104. users = get_user_model().objects
Exception Type: AttributeError at /accounts/google/login/callback/
Exception Value: type object 'User' has no attribute 'objects'
In models.py :
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=250, unique=True)
username = models.CharField(max_length=250, null=True)
created_date = models.DateTimeField(auto_now_add=True, null=True)
is_active = models.NullBooleanField(default=True, null=True)
is_staff = models.NullBooleanField(default=False, null=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
object = UserManager()
def get_full_name(self):
return self.email
def get_short_name(self):
return self.email
def __str__(self):
return '{} ( {} )'.format(self.email, self.username)
class Meta:
swappable = 'AUTH_USER_MODEL'
In settings.py :
# django-allauth settings
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'facebook':
{'METHOD': 'oauth2',
'SCOPE': ['email'],
'FIELDS': [
'email',
'name',
'first_name',
'last_name',
'verified',
'updated_time'],
'VERIFIED_EMAIL': False,
'VERSION': 'v2.4'},
'google':
{'SCOPE': ['profile', 'email', 'https://www.googleapis.com/auth/userinfo.email'],
'AUTH_PARAMS': {
'access_type': 'online'
}
}
}
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
Upvotes: 1
Views: 1965
Reputation: 31
Therefore, if your custom user model does not have a username field, you will need to set ACCOUNT_USER_MODEL_USERNAME_FIELD
to None
. This will disable username related functionality in allauth. Remember to also set ACCOUNT_USERNAME_REQUIRED
to False
.
For more information see the docs: https://django-allauth.readthedocs.io/en/latest/advanced.html
Upvotes: 3
Reputation: 137
Sorry. There was a mis-spelling mistake.. I changed "object" to "objects" in my User class..
Upvotes: 0