-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Populate User name
field during social auth
#3968
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an exemple of a social provider I could use to test this without too much setup? Also, it would be nice if we could write an automated test for it, this is
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py
Outdated
Show resolved
Hide resolved
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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seems like it would be more consistent with django-allauth if we were to do it in the save_user()
method: https://github.com/pennersr/django-allauth/blob/7060e3fb6e00f01bd881890546244670929b5cf3/allauth/account/adapter.py#L224-L251
Unless there a specific reason not to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been awhile, but I believe save_user
isn't actually used for social registration (i.e. it's not called if you use auto signup):
save_user(self, request, sociallogin, form=None): Populates and saves the User instance (and related social login data). The signup form is not available in case of auto signup.
Thanks for the review
I find Google the easiest and Twitter the second easiest to set up.
We could add mock requests? Otherwise, not sure whether adding these OAuth providers and a bot for automated testing will trigger a captcha warning. |
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/adapters.py
Outdated
Show resolved
Hide resolved
name
field during social auth
Description
The "name" field is not filled with social authentication using django allauth due to removing the first and last name field in the User model. This PR fills in the name field.
Checklist:
Rationale
To fill in the name field during social auth