From 7d54daf738c0cdb6787c1e03b36a253be596dff9 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sun, 8 May 2022 03:45:00 -0400 Subject: [PATCH 1/2] By default, set the fullname from first+last and vice-versa Fixes #678. --- social_core/pipeline/__init__.py | 2 ++ social_core/pipeline/social_auth.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/social_core/pipeline/__init__.py b/social_core/pipeline/__init__.py index 5ff422be6..2d9969320 100644 --- a/social_core/pipeline/__init__.py +++ b/social_core/pipeline/__init__.py @@ -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", diff --git a/social_core/pipeline/social_auth.py b/social_core/pipeline/social_auth.py index 1c5940e75..8159edd76 100644 --- a/social_core/pipeline/social_auth.py +++ b/social_core/pipeline/social_auth.py @@ -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))} From 87949c3f54d4775da03911b7d3233dab8283f0e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 13 Jul 2024 07:35:38 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- social_core/pipeline/__init__.py | 2 +- social_core/pipeline/social_auth.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/social_core/pipeline/__init__.py b/social_core/pipeline/__init__.py index 2d9969320..ff4bbefd1 100644 --- a/social_core/pipeline/__init__.py +++ b/social_core/pipeline/__init__.py @@ -5,7 +5,7 @@ # 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', + "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", diff --git a/social_core/pipeline/social_auth.py b/social_core/pipeline/social_auth.py index 8159edd76..12238d38e 100644 --- a/social_core/pipeline/social_auth.py +++ b/social_core/pipeline/social_auth.py @@ -7,17 +7,17 @@ def social_details(backend, details, response, *args, **kwargs): 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() + 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'] + 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):