dar*_*der 2 python django django-allauth
我正在使用 django all-auth 包来允许人们通过 g+ oauth2 登录。问题在于,在服务器上,登录会导致其重定向到 /accounts/social/signup 页面,而不是直接登录并返回主页。
这是所需的代码详细信息
设置.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'
Run Code Online (Sandbox Code Playgroud)
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')))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2451 次 |
| 最近记录: |