File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
from django .http import HttpRequest
2
2
from django .conf import settings
3
3
from django .utils .translation import ugettext_lazy as _
4
+ from django .contrib .auth import get_user_model
4
5
5
6
try :
6
7
from allauth .account import app_settings as allauth_settings
@@ -111,6 +112,20 @@ def validate(self, attrs):
111
112
raise serializers .ValidationError (_ ('Incorrect value' ))
112
113
113
114
if not login .is_existing :
115
+ # We have an account already signed up in a different flow
116
+ # with the same email address: raise an exception.
117
+ # This needs to be handled in the frontend. We can not just
118
+ # link up the accounts due to security constraints
119
+ if (allauth_settings .UNIQUE_EMAIL ):
120
+ # Do we have an account already with this email address?
121
+ existing_account = get_user_model ().objects .filter (
122
+ email = login .user .email ,
123
+ ).count ()
124
+ if (existing_account != 0 ):
125
+ # There is an account already
126
+ raise serializers .ValidationError (
127
+ _ ("A user is already registered with this e-mail address." ))
128
+
114
129
login .lookup ()
115
130
login .save (request , connect = True )
116
131
attrs ['user' ] = login .account .user
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ django-allauth>=0.25.0
2
2
responses>=0.3.0
3
3
flake8==2.4.0
4
4
djangorestframework-jwt>=1.7.2
5
+ djangorestframework>=3.6.4
Original file line number Diff line number Diff line change @@ -275,8 +275,12 @@ def test_edge_case(self):
275
275
'access_token' : 'abc123'
276
276
}
277
277
278
- self .post (self .fb_login_url , data = payload , status_code = 200 )
279
- self .assertIn ('key' , self .response .json .keys ())
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
+ 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())
280
284
281
285
@responses .activate
282
286
@override_settings (
You can’t perform that action at this time.
0 commit comments