Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3cfc739

Browse files
committedMay 8, 2022
By default, set the fullname from first+last and vice-versa
Fixes #678.
1 parent f27461d commit 3cfc739

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
 

‎social_core/pipeline/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# could hit a provider API.
66
'social_core.pipeline.social_auth.social_details',
77

8+
# Populate first+last name from full name and vice-versa, if needed
9+
'social_core.pipeline.social_auth.social_names',
10+
811
# Get the social uid from whichever service we're authing thru. The uid is
912
# the unique identifier of the given user in the provider.
1013
'social_core.pipeline.social_auth.social_uid',

‎social_core/pipeline/social_auth.py

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ def social_details(backend, details, response, *args, **kwargs):
55
return {'details': dict(backend.get_user_details(response), **details)}
66

77

8+
def social_names(backend, details, response, *args, **kwargs):
9+
# If first+last are both missing, populate from full
10+
if details.get('fullname') and backend.setting('FIRSTLAST_FROM_FULL', True):
11+
if not (details.get('first_name') or details.get('last_name')):
12+
first, _space, last = details['fullname'].rpartition(' ')
13+
details['first_name'] = first.strip()
14+
details['last_name'] = last.strip()
15+
print(f"end social_names {details=}")
16+
17+
# If first+last are both present, populate full if that's missing
18+
if not details.get('fullname') and backend.setting('FULL_FROM_FIRSTLAST', True):
19+
if details.get('first_name') and details.get('last_name'):
20+
details['fullname'] = details['first_name'] + " " + details['last_name']
21+
22+
823
def social_uid(backend, details, response, *args, **kwargs):
924
return {'uid': backend.get_user_id(details, response)}
1025

0 commit comments

Comments
 (0)
Please sign in to comment.