Commit 99398fc0 authored by Michal Čihař's avatar Michal Čihař

Properly import full name from third party services

We now correctly store full name in first_name attribute regardless of
what the service actually provides.

Closes #426
parent 526adf54
......@@ -98,3 +98,31 @@ def store_email(strategy, user, social, details, *args, **kwargs):
if verified.email != details['email']:
verified.email = details['email']
verified.save()
def user_full_name(strategy, details, response, user=None, *args, **kwargs):
"""
Update user full name using data from provider.
"""
print 'pipe', user, details
if user:
full_name = ''
if 'fullname' in details:
full_name = details['fullname']
elif 'first_name' in details or 'last_name' in details:
first_name = details.get('first_name', '')
last_name = details.get('last_name', '')
if first_name and not first_name in last_name:
full_name = u'{0} {1}'.format(first_name, last_name)
elif first_name:
full_name = first_name
else:
full_name = last_name
full_name = full_name.strip()
if full_name != user.first_name:
user.first_name = full_name
strategy.storage.user.changed(user)
......@@ -196,7 +196,7 @@ SOCIAL_AUTH_PIPELINE = (
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'weblate.accounts.pipeline.user_full_name',
'weblate.accounts.pipeline.store_email',
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment