Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

By default, set the fullname from first+last and vice-versa #683

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions social_core/pipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# 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=}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'll need to remove this, but I'd like to confirm that the general direction seems good before I do the cleanup.)


# 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': backend.get_user_id(details, response)}

Expand Down