mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-22 09:06:40 +03:00
added fix to the same users email from Twitter as already registered in different flow
This commit is contained in:
parent
658664a7d4
commit
040874b592
|
@ -1,9 +1,12 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.http import HttpRequest
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
# Import is needed only if we are using social login, in which
|
||||
# case the allauth.socialaccount will be declared
|
||||
if 'allauth.socialaccount' in settings.INSTALLED_APPS:
|
||||
from allauth.account import app_settings as allauth_settings
|
||||
from allauth.socialaccount.helpers import complete_social_login
|
||||
from allauth.socialaccount.models import SocialToken
|
||||
from allauth.socialaccount.providers.oauth.client import OAuthError
|
||||
|
@ -68,6 +71,20 @@ class TwitterLoginSerializer(serializers.Serializer):
|
|||
raise serializers.ValidationError(str(e))
|
||||
|
||||
if not login.is_existing:
|
||||
# We have an account already signed up in a different flow
|
||||
# with the same email address: raise an exception.
|
||||
# This needs to be handled in the frontend. We can not just
|
||||
# link up the accounts due to security constraints
|
||||
if allauth_settings.UNIQUE_EMAIL:
|
||||
# Do we have an account already with this email address?
|
||||
account_exists = get_user_model().objects.filter(
|
||||
email=login.user.email,
|
||||
).exists()
|
||||
if account_exists:
|
||||
raise serializers.ValidationError(
|
||||
_("User is already registered with this e-mail address.")
|
||||
)
|
||||
|
||||
login.lookup()
|
||||
login.save(request, connect=True)
|
||||
attrs['user'] = login.account.user
|
||||
|
|
Loading…
Reference in New Issue
Block a user