重写身份验证方法 - Django admin
我正在尝试找出如何通过附加功能来增强身份验证方法。
例如,
- 过期密码、
- 特殊密码格式
- 长度要求
- 等...
对于网站的前端来说非常简单,但是管理面板呢?
我认为我应该覆盖用户管理器对象,因为可能需要进行身份验证居住在那里。我认为这是一个很难弄清楚的问题。
提前致谢! :)
I'm trying to figure out how to enhance the authenticate method with additional functionality.
e.g.
- Expiring passwords
- special password formats
- length requirements
- etc...
It is pretty straight forward for the site's frontend, but what about the admin panel?
I reckon that I should override the User's Manager object, as authenticate probably resides there. This is quite a tough one to figure out I think.
Thanks in advance! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以按照 http://docs 中的说明创建自定义身份验证后端.djangoproject.com/en/dev/topics/auth/#authentication-backends。本质上,您创建一个具有
authenticate
方法的后端类:然后将该类添加到
settings.py
中的AUTHENTICATION_BACKENDS
。尽管这是用于身份验证,但例如,如果密码正确但已过期,您可以通过将用户重定向到更改密码页面来完成您提到的所有密码验证操作。考虑使用消息传递框架来向用户提示什么是当引导他进入通用更改密码页面时发生的情况。
You can create custom authentication backend by following the instructions in http://docs.djangoproject.com/en/dev/topics/auth/#authentication-backends. Essentially, you create a backend class that has an
authenticate
method:Then add the class to
AUTHENTICATION_BACKENDS
insettings.py
.Though this is for authentication, you could do all the password validation things you mentioned simply by redirecting a user to a change password page if the password is correct but expired, for instance. Consider using the messaging framework to give a user a hint about what is going on when directing him to a generic change password page.
如果您希望将密码验证内置到模型中,那么您可能需要 扩展 django 用户模型。
否则,您可以执行以下操作:
(r'^admin/', include(admin.site.urls)) 上方
。正则表达式类似于(r'^admin/auth/user/(\d+)/password/', new_change_password)
。If you want the validation for passwords to be built into the model, then you'll probably want to extend the django User model.
Otherwise, you could do the following:
(r'^admin/', include(admin.site.urls))
. Regex would look something like(r'^admin/auth/user/(\d+)/password/', new_change_password)
.