Skip to content

Commit

Permalink
By default, set the fullname from first+last and vice-versa
Browse files Browse the repository at this point in the history
Fixes #678.
  • Loading branch information
dehnert committed Jul 13, 2024
1 parent 3449faf commit 7d54daf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions social_core/pipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# already part of the auth response from the provider, but sometimes this
# could hit a provider API.
"social_core.pipeline.social_auth.social_details",
# Populate first+last name from full name and vice-versa, if needed
'social_core.pipeline.social_auth.social_names',
# Get the social uid from whichever service we're authing thru. The uid is
# the unique identifier of the given user in the provider.
"social_core.pipeline.social_auth.social_uid",
Expand Down
15 changes: 15 additions & 0 deletions social_core/pipeline/social_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ def social_details(backend, details, response, *args, **kwargs):
return {"details": dict(backend.get_user_details(response), **details)}


def social_names(backend, details, response, *args, **kwargs):
# If first+last are both missing, populate from full
if details.get('fullname') and backend.setting('FIRSTLAST_FROM_FULL', True):
if not (details.get('first_name') or details.get('last_name')):
first, _space, last = details['fullname'].rpartition(' ')
details['first_name'] = first.strip()
details['last_name'] = last.strip()
print(f"end social_names {details=}")

# If first+last are both present, populate full if that's missing
if not details.get('fullname') and backend.setting('FULL_FROM_FIRSTLAST', True):
if details.get('first_name') and details.get('last_name'):
details['fullname'] = details['first_name'] + " " + details['last_name']


def social_uid(backend, details, response, *args, **kwargs):
return {"uid": str(backend.get_user_id(details, response))}

Expand Down

0 comments on commit 7d54daf

Please sign in to comment.