darkryder
darkryder

Reputation: 832

Django allauth redirects to signup

I'm using the django all-auth package to allow people to login through g+ oauth2. The problem is that on the server, logging in causes it to redirect to the /accounts/social/signup page, instead of directly logging in and going back to the home page.

Here's the required code details

settings.py

LOGIN_URL = '/accounts/google/login/'
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_PROVIDERS = {
    'google': {
    'SCOPE': [
    'https://www.googleapis.com/auth/userinfo.email',
     'https://www.googleapis.com/auth/userinfo.profile',
     'https://www.googleapis.com/auth/plus.login',
     'https://www.googleapis.com/auth/plus.me'
     ],
     'AUTH_PARAMS': {'access_type': 'online'}
    }
}
SOCIALACCOUNT_ADAPTER = 'lostndfound.views.LoginAdapter'

lostndfound.views

class LoginAdapter(DefaultSocialAccountAdapter):
    def pre_social_login(self, request, sociallogin):
        user = sociallogin.account.user
        if user.email.split('@')[-1] not in settings.ALLOWED_LOGIN_HOSTS:
            messages.error(request, "You can login only through an *** account.")
            raise ImmediateHttpResponse(HttpResponseRedirect(reverse('home')))

Upvotes: 2

Views: 2610

Answers (2)

Aby Johnson
Aby Johnson

Reputation: 1

Make sure the Email id you tried to log in with google is previously stored in DB in any other way. If there then remove it and try once more.

Upvotes: 0

darkryder
darkryder

Reputation: 832

I had used my email id I was trying to login through as the email id of the superuser of the admin site. This was causing a conflict as the email was not unique. I simply changed my email of the superuser.

Upvotes: 5

Related Questions