Milano
Milano

Reputation: 18705

Django AllAuth - Google - choose username

We are using Django-allauth to allow users to signup and login using Google.

The problem is that it automatically chooses first name from Google account as a username.

Is it possible to make users to fill the username manually?

I didn't find such settings in Allauth-google docs.

These are ACCOUNT_ settings from settings.py

ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_EMAIL_SUBJECT_PREFIX = EMAIL_SUBJECT_PREFIX
ACCOUNT_EMAIL_CONFIRMATION_COOLDOWN = 1
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
ACCOUNT_PRESERVE_USERNAME_CASING = False
ACCOUNT_USERNAME_MIN_LENGTH = 4
ACCOUNT_USERNAME_REQUIRED = True

There is no such setting starting SOCIALACCOUNT_ in Docs.

Upvotes: 5

Views: 1146

Answers (1)

Victoria
Victoria

Reputation: 31

You need to make sure that allauth doesn't try to bypass the signup form.

In settings.py:

SOCIALACCOUNT_AUTO_SIGNUP = False

This will redirect the user to the default signup page and have a signup form where the user can choose their username. SOCIALACCOUNT_AUTO_SIGNUP django-allauth readthedocs explanation

If you want, you can also customize the signup form for a user signing up with a social account by doing the following:

In settings.py:

SOCIALACCOUNT_FORMS = {
    'signup': 'mysite.forms.MyCustomSocialSignupForm',
}

In your models file:

from allauth.socialaccount.forms import SignupForm
class MyCustomSocialSignupForm(SignupForm):

    def save(self, request):

        # Ensure you call the parent class's save.
        # .save() returns a User object.
        user = super(MyCustomSocialSignupForm, self).save(request)

        # Add your own processing here.

        # You must return the original result.
        return user

and then you can add any custom changes to this form that are needed

django-allauth readthedocs for overriding default signup form

Upvotes: 3

Related Questions