[Python] Password doesnt get saved from the signup request in django-allauth

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have a django app and i am using django-allauth to authenticate users.I dont have anything complex setup right now, all i am trying to do is let the user signup through email and password and verify their email before they can login.

    I am testing the apis through postman right now and when i hit the singup endpoint, everything works fine: the user object is saved in database with the relevant fields(email, phone number, role) but the password does not get saved and because of this i am not able to login or do anything else in the authentication process.

    This is my setup:

    I am using the headless apis rather than regular ones. This is my settings.py


    INSTALLED_APPS = [
    ....
    'allauth',
    'allauth.account',
    'allauth.headless',
    'allauth.usersessions',
    ]

    AUTHENTICATION_BACKENDS = [
    # `allauth` specific authentication methods, such as login by email
    'allauth.account.auth_backends.AuthenticationBackend',
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend'
    ]

    #ALLAUTH SETTINGS
    ACCOUNT_EMAIL_VERIFICATION = "mandatory"
    ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED = True
    ACCOUNT_SIGNUP_FIELDS = [
    'email*',
    'phone*',
    'password*',
    ]
    ACCOUNT_SIGNUP_FORM_CLASS = "user_onboarding.forms.CustomSignupForm"
    ACCOUNT_ADAPTER = 'user_onboarding.adapter.CustomAccountAdapter'
    ACCOUNT_LOGIN_METHODS = {"email"}
    HEADLESS_ONLY = True
    HEADLESS_FRONTEND_URLS = {
    "account_confirm_email": "/account/verify-email/{key}",
    "account_reset_password": "/account/password/reset",
    "account_reset_password_from_key": "/account/password/reset/key/{key}",
    "account_signup": "/account/signup",
    "socialaccount_login_error": "/account/provider/callback",
    }

    ACCOUNT_PHONE_VERIFICATION_ENABLED = False


    form.py

    class CustomSignupForm(forms.Form):
    role = forms.CharField(max_length=50)
    def signup(self, request, user):
    user.role = self.cleaned_data['role']
    user.save()


    adapter.py

    from allauth.account.adapter import DefaultAccountAdapter

    class CustomAccountAdapter(DefaultAccountAdapter):
    def set_phone(self, user, phone: str, verified: bool):
    # map the incoming "phone" value onto your CustomUser.phone_number
    user.phone_number = phone
    user.save()

    def get_phone(self, user):
    if user.phone_number:
    return user.phone_number, True
    return None



    urls.py

    urlpatterns = [
    path('list-urls/', list_urls, name='list_urls'),
    path("_allauth/", include("allauth.headless.urls")),
    ....
    ]


    and this is the signup request that i am making

    curl --location 'http://0.0.0.0:8080/api/_allauth/browser/v1/auth/signup' \
    --header 'X-CSRFToken: nALgtSOEx2J0neAIzw2BFASadoM5FwN9' \
    --header 'Content-Type: application/json' \
    --header 'Cookie: csrftoken=nALgtSOEx2J0neAIzw2BFASadoM5FwN9; sessionid=er7b190l2n04rvif873t2w2x8rkj3i5o' \
    --data-raw '{
    "email": "umansafor@gmail.com",
    "password": "passabcd1",
    "phone": "+911234567899",
    "role": "USERS"
    }'


    i get a 401 unauthorized response for this request which is expected but in the database the password the user is not being saved all the other fields are saved properly

    p.s this is my users model

    class CustomUser(AbstractBaseUser, PermissionsMixin):
    ROLE_CHOICES = [
    ("USERS", "Users"),
    ("USER_KIN", "User Kin"),
    ("CARE_MANAGER", "Care Manager"),
    ("ADMIN", "Admin"),
    ("ENG_TEAM", "Engineering Team"),
    ]
    phone_number = models.CharField(max_length=15, unique=True, blank=True, null=True)
    email = models.EmailField(unique=True, null=True, blank=True)
    username = models.CharField(max_length=50, unique=True)
    role = models.CharField(max_length=20, choices=ROLE_CHOICES, default="USERS")
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)
    objects = CustomUserManager()
    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []
    def __str__(self):
    return self.username

    Continue reading...

Compartilhe esta Página