Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-allauth set username the same as email

I have a sign up form which asks only for email and password. When a user signs up, django-allauth creates a username for that user by striping the "@email" suffix form the user's email address.

So for example, if a user signs up with "[email protected]" his username will be "some-user" and if another user signs up with "[email protected]" then his username will be "some-userr"

But what I want is the username and email of the users to have the same value.

So how can I configure django-allauth to set the usernames as the users emails without striping their suffixes?

And if possible, how can I do that without creating a custom user.

In my settings.py:

#########################
# AllAuth Configuration #
#########################
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_PASSWORD_MIN_LENGTH = 8
like image 550
GregC Avatar asked Dec 07 '14 22:12

GregC


1 Answers

profiles.models.py (custom user model)

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):

    def populate_user(self, request, sociallogin, data):
        user = super().populate_user(request, sociallogin, data)
        user.username = user.email
        return user

settings.py

SOCIALACCOUNT_ADAPTER = "profiles.models.CustomSocialAccountAdapter"
like image 191
Min ho Kim Avatar answered Sep 28 '22 11:09

Min ho Kim