File tree Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -116,18 +116,19 @@ def validate(self, attrs):
116
116
# with the same email address: raise an exception.
117
117
# This needs to be handled in the frontend. We can not just
118
118
# link up the accounts due to security constraints
119
- if ( allauth_settings .UNIQUE_EMAIL ) :
119
+ if allauth_settings .UNIQUE_EMAIL :
120
120
# Do we have an account already with this email address?
121
- existing_account = get_user_model ().objects .filter (
121
+ account_exists = get_user_model ().objects .filter (
122
122
email = login .user .email ,
123
- ).count ()
124
- if (existing_account != 0 ):
125
- # There is an account already
123
+ ).exists ()
124
+ if account_exists :
126
125
raise serializers .ValidationError (
127
- _ ("A user is already registered with this e-mail address." ))
126
+ _ ("User is already registered with this e-mail address." )
127
+ )
128
128
129
129
login .lookup ()
130
130
login .save (request , connect = True )
131
+
131
132
attrs ['user' ] = login .account .user
132
133
133
134
return attrs
Original file line number Diff line number Diff line change @@ -225,7 +225,7 @@ def test_twitter_social_auth_no_adapter(self):
225
225
REST_SESSION_LOGIN = False ,
226
226
ACCOUNT_EMAIL_CONFIRMATION_HMAC = False
227
227
)
228
- def test_edge_case (self ):
228
+ def test_email_clash_with_existing_account (self ):
229
229
resp_body = {
230
230
"id" : "123123123123" ,
231
231
"first_name" : "John" ,
@@ -251,6 +251,8 @@ def test_edge_case(self):
251
251
252
252
# test empty payload
253
253
self .post (self .register_url , data = {}, status_code = 400 )
254
+
255
+ # register user and send email confirmation
254
256
self .post (
255
257
self .register_url ,
256
258
data = self .REGISTRATION_DATA ,
@@ -271,16 +273,11 @@ def test_edge_case(self):
271
273
self ._login ()
272
274
self ._logout ()
273
275
276
+ # fb log in with already existing email
274
277
payload = {
275
278
'access_token' : 'abc123'
276
279
}
277
-
278
- # You should not have access to an account created through register
279
- # by loging in through FB with an account that has the same
280
- # email address.
281
280
self .post (self .fb_login_url , data = payload , status_code = 400 )
282
- # self.post(self.fb_login_url, data=payload, status_code=200)
283
- # self.assertIn('key', self.response.json.keys())
284
281
285
282
@responses .activate
286
283
@override_settings (
You can’t perform that action at this time.
0 commit comments