帐户不活动页面在Django-Allauth中不起作用

发布于 2025-01-22 17:39:28 字数 262 浏览 1 评论 0原文

我已经使用流行的Django-Allauth软件包成功设置了使用Django应用程序的身份验证系统。我通过更新hespendeduser.is_active = false暂停了注册用户正确。。 我是否需要任何特殊的配置来显示account_inactive.html模板,因为我找不到在官方文档中提到的任何内容?

注意: django-allauth版本为0.49.0,django版本为4.0.3

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

于我来说 2025-01-29 17:39:28

您可以覆盖Django-Allauth的登录功能。您可以在用户模型名称下创建一个dield is_suspended,而不是给出is_Active = false。在登录函数中,登录()放置一个if语句。

#in django-allauth login function

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

渲染(请求,'user/user_policy.html'{'messages':message})

或搜索 django-alluth信号

#in User model:

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

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)
橘寄 2025-01-29 17:39:28

在查看配置后,我意识到我在settings.py文件中使用了自定义身份验证后端。 django-allauth需要allauth.account.auth_backends.authenticationbackend来处理身份验证和权限。

将其添加到我的项目配置中解决了该问题,

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',
   
]

尽管在

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文