Skip to content

Commit 7d54daf

Browse files
committed
By default, set the fullname from first+last and vice-versa
Fixes python-social-auth#678.
1 parent 3449faf commit 7d54daf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

social_core/pipeline/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# already part of the auth response from the provider, but sometimes this
55
# could hit a provider API.
66
"social_core.pipeline.social_auth.social_details",
7+
# Populate first+last name from full name and vice-versa, if needed
8+
'social_core.pipeline.social_auth.social_names',
79
# Get the social uid from whichever service we're authing thru. The uid is
810
# the unique identifier of the given user in the provider.
911
"social_core.pipeline.social_auth.social_uid",

social_core/pipeline/social_auth.py

Lines changed: 15 additions & 0 deletions
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": str(backend.get_user_id(details, response))}
1025

0 commit comments

Comments
 (0)