summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2019-01-10 13:33:45 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2019-01-10 13:33:45 +0100
commit6b91ed4d257e7972ebc24deda96dc90698fb4db4 (patch)
tree7204c61e2a535921e3c7df76b6036937f88bb941
parent638ea2a2aa1a90a2bdd6c7b795a2e89ed572d2e8 (diff)
downloadspejstore-6b91ed4d257e7972ebc24deda96dc90698fb4db4.tar.gz
spejstore-6b91ed4d257e7972ebc24deda96dc90698fb4db4.tar.bz2
spejstore-6b91ed4d257e7972ebc24deda96dc90698fb4db4.zip
Fix account associations by email
-rw-r--r--auth/backend.py10
-rw-r--r--auth/pipeline.py9
-rw-r--r--spejstore/settings.py1
3 files changed, 17 insertions, 3 deletions
diff --git a/auth/backend.py b/auth/backend.py
index 25c6d65..363923c 100644
--- a/auth/backend.py
+++ b/auth/backend.py
@@ -15,17 +15,21 @@ class HSWawOAuth2(BaseOAuth2):
]
def get_user_details(self, response):
- """Return user details from GitHub account"""
+ """Return user details from Hackerspace account"""
+ personal_email = None
+ if response.get('personal_email'):
+ personal_email = response.get('personal_email')[0]
+
return {'username': response.get('username'),
'email': response.get('email'),
+ 'personal_email': personal_email,
}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
url = 'https://sso.hackerspace.pl/api/1/profile'
headers = {
- 'Authorization': 'Bearer {}'.format(access_token)
-
+ 'Authorization': 'Bearer {}'.format(access_token)
}
return self.get_json(url, headers=headers)
diff --git a/auth/pipeline.py b/auth/pipeline.py
index 74f6918..8895810 100644
--- a/auth/pipeline.py
+++ b/auth/pipeline.py
@@ -1,3 +1,12 @@
+from social_core.pipeline.social_auth import associate_by_email
+
+
def staff_me_up(backend, details, response, uid, user, *args, **kwargs):
user.is_staff = True
user.save()
+
+
+def associate_by_personal_email(backend, details, user=None, *args, **kwargs):
+ return associate_by_email(backend, {
+ 'email': details.get('personal_email'),
+ }, user, *args, **kwargs)
diff --git a/spejstore/settings.py b/spejstore/settings.py
index 4a1b11c..f5ea2fc 100644
--- a/spejstore/settings.py
+++ b/spejstore/settings.py
@@ -135,6 +135,7 @@ SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
+ 'auth.pipeline.associate_by_personal_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',