Skip to content

Commit

Permalink
pep8 cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mariodev committed Nov 12, 2017
1 parent 945008d commit f89471f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
13 changes: 7 additions & 6 deletions rest_auth/registration/serializers.py
Expand Up @@ -116,18 +116,19 @@ def validate(self, attrs):
# 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):
if allauth_settings.UNIQUE_EMAIL:
# Do we have an account already with this email address?
existing_account = get_user_model().objects.filter(
account_exists = get_user_model().objects.filter(
email=login.user.email,
).count()
if(existing_account != 0):
# There is an account already
).exists()
if account_exists:
raise serializers.ValidationError(
_("A user is already registered with this e-mail address."))
_("User is already registered with this e-mail address.")
)

login.lookup()
login.save(request, connect=True)

attrs['user'] = login.account.user

return attrs
Expand Down
11 changes: 4 additions & 7 deletions rest_auth/tests/test_social.py
Expand Up @@ -225,7 +225,7 @@ def test_twitter_social_auth_no_adapter(self):
REST_SESSION_LOGIN=False,
ACCOUNT_EMAIL_CONFIRMATION_HMAC=False
)
def test_edge_case(self):
def test_email_clash_with_existing_account(self):
resp_body = {
"id": "123123123123",
"first_name": "John",
Expand All @@ -251,6 +251,8 @@ def test_edge_case(self):

# test empty payload
self.post(self.register_url, data={}, status_code=400)

# register user and send email confirmation
self.post(
self.register_url,
data=self.REGISTRATION_DATA,
Expand All @@ -271,16 +273,11 @@ def test_edge_case(self):
self._login()
self._logout()

# fb log in with already existing email
payload = {
'access_token': 'abc123'
}

# You should not have access to an account created through register
# by loging in through FB with an account that has the same
# email address.
self.post(self.fb_login_url, data=payload, status_code=400)
# self.post(self.fb_login_url, data=payload, status_code=200)
# self.assertIn('key', self.response.json.keys())

@responses.activate
@override_settings(
Expand Down

0 comments on commit f89471f

Please sign in to comment.