Fix account associations by email
This commit is contained in:
parent
638ea2a2aa
commit
6b91ed4d25
|
@ -15,17 +15,21 @@ class HSWawOAuth2(BaseOAuth2):
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_user_details(self, response):
|
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'),
|
return {'username': response.get('username'),
|
||||||
'email': response.get('email'),
|
'email': response.get('email'),
|
||||||
|
'personal_email': personal_email,
|
||||||
}
|
}
|
||||||
|
|
||||||
def user_data(self, access_token, *args, **kwargs):
|
def user_data(self, access_token, *args, **kwargs):
|
||||||
"""Loads user data from service"""
|
"""Loads user data from service"""
|
||||||
url = 'https://sso.hackerspace.pl/api/1/profile'
|
url = 'https://sso.hackerspace.pl/api/1/profile'
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Bearer {}'.format(access_token)
|
'Authorization': 'Bearer {}'.format(access_token)
|
||||||
|
|
||||||
}
|
}
|
||||||
return self.get_json(url, headers=headers)
|
return self.get_json(url, headers=headers)
|
||||||
|
|
||||||
|
|
|
@ -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):
|
def staff_me_up(backend, details, response, uid, user, *args, **kwargs):
|
||||||
user.is_staff = True
|
user.is_staff = True
|
||||||
user.save()
|
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)
|
||||||
|
|
|
@ -135,6 +135,7 @@ SOCIAL_AUTH_PIPELINE = (
|
||||||
'social_core.pipeline.social_auth.social_user',
|
'social_core.pipeline.social_auth.social_user',
|
||||||
'social_core.pipeline.user.get_username',
|
'social_core.pipeline.user.get_username',
|
||||||
'social_core.pipeline.social_auth.associate_by_email',
|
'social_core.pipeline.social_auth.associate_by_email',
|
||||||
|
'auth.pipeline.associate_by_personal_email',
|
||||||
'social_core.pipeline.user.create_user',
|
'social_core.pipeline.user.create_user',
|
||||||
'social_core.pipeline.social_auth.associate_user',
|
'social_core.pipeline.social_auth.associate_user',
|
||||||
'social_core.pipeline.social_auth.load_extra_data',
|
'social_core.pipeline.social_auth.load_extra_data',
|
||||||
|
|
Loading…
Reference in New Issue