Fix account associations by email

This commit is contained in:
Piotr Dobrowolski 2019-01-10 13:33:45 +01:00
parent 638ea2a2aa
commit 6b91ed4d25
3 changed files with 17 additions and 3 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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',