[英]Django allauth redirects to signup
我正在使用 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'
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')))
我曾使用我嘗試登錄的電子郵件 ID 作為管理站點超級用戶的電子郵件 ID。 這導致了沖突,因為電子郵件不是唯一的。 我只是更改了超級用戶的電子郵件。
確保您嘗試使用 google 登錄的電子郵件 ID 之前以任何其他方式存儲在數據庫中。 如果有,則將其刪除並再次嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.