如何设置django-registration需要手动激活账户?
如何设置 django-registration 需要管理员手动激活帐户?
帐户持有者单击电子邮件中的链接后,我希望向管理员发送一封电子邮件,并且他还需要单击一个链接,然后帐户才会激活。
django-registration 是否可以,或者我需要使用其他东西,以及使用什么?
How to set-up django-registration that an account needs to be manually activated by an admin?
After the account-holder clicks in the link in the e-mail I would like that an e-mail is sent to the admin, and he also needs to click a link and only then the account would be active.
Is it possible with django-registration, or do I need to use something else, and what to use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
django-registration 允许您编写自定义后端来处理自定义激活需求。
因此,您要做的就是创建自己的后端,自己实现
注册
和激活
。下面是如何实现
register
函数的示例:关键点是确保
send_email
设置为 false;这将阻止用户获得激活链接。然后,您可以决定发送给管理员的电子邮件是否包含激活链接,或者您是否同意他们转到管理员并仅选中“活动”框。如果您使用
django.contrib.auth
中的AuthenticationForm
那么它会自动拒绝is_active
为 False 的用户,但如果您不使用它然后确保对需要活动用户的任何请求运行以下检查:您还可以编写自己的装饰器(查看
@login_required
以获取指针)。请注意,@login_required
不会检查is_active
。django-registration allows you to write a custom backend to handle custom activation needs.
So what you'd do is create your own backend, implementing the
register
andactivate
yourself.Here's an example of how you could implement the
register
function:The key point is to make sure
send_email
is set to false; that will prevent the user from getting an activation link. Then you can decide whether the email sent to the admins has an activation link or if you're content with them going to admin and just checking the "Active" box.If you use
AuthenticationForm
fromdjango.contrib.auth
then it will automatically reject users whoseis_active
is False, but if you're not using that then make sure to run the following check for any request where an active user is required:You can also write your own decorator (look at
@login_required
for pointers). Note that@login_required
does not check foris_active
.