Home > Back-end >  Account Inactive Page Not Working in django-allauth
Account Inactive Page Not Working in django-allauth

Time:04-20

I have successfully setup an authentication system with django application using the popular django-allauth package. I suspended a registered user by updating SuspendedUser.is_active=False but whenever I try to login as the suspended user I'd get the failed authentication message The username and/or password you specified are not correct.. Do I need any special configuration to display the account_inactive.html template as I cannot find anything that mentions that in the official documentation?.

Note: django-allauth version is 0.49.0 and django version is 4.0.3

CodePudding user response:

You can override log-in function of django-allauth. And you can create a dield under your user model names is_suspended instead of giving is_active=False. And in login function before login() put an if statement.

#in django-allauth login function

if request.user.is_suspended:
    message(request,'You have suspended! Cannot login!')
    return

render(request, 'user/user_policy.html' {'message':message})

or search django-alluth signals

#in User model:

class User(models.Model):
     ...
     ...
     ...
     is_suspended = models.BooleanField(default=False)

CodePudding user response:

After reviewing my configurations, I realized I was using a custom authentication backend in my settings.py file. django-allauth requires allauth.account.auth_backends.AuthenticationBackend to handle authentication and permissions.

Adding this to my project config solved the problem

AUTHENTICATION_BACKENDS = [
   
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
   
]

Although it was stated in the docs

  • Related