Populate user name field in social auth

This commit is contained in:
Andrew Chen Wang 2022-11-28 01:23:35 -05:00 committed by GitHub
parent 0a8b15615a
commit 541f09ab55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,3 +14,13 @@ class AccountAdapter(DefaultAccountAdapter):
class SocialAccountAdapter(DefaultSocialAccountAdapter): class SocialAccountAdapter(DefaultSocialAccountAdapter):
def is_open_for_signup(self, request: HttpRequest, sociallogin: Any): def is_open_for_signup(self, request: HttpRequest, sociallogin: Any):
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True) return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
def populate_user(self, request, sociallogin, data):
user = sociallogin.user
if name := data.get("name"):
user.name = name
elif first_name := data.get("first_name"):
user.name = first_name
if last_name := data.get("last_name"):
user.name += f" {last_name}"
return super().populate_user(request, sociallogin, data)