4

我即将创建一个监控注册的网站,只允许某些人注册。毫无疑问,尽管我在注册表上方写了任何文字,但仍有一些不合适的人会注册,所以我们要适度。

注册后django.contrib.auth User,将创建一个和个人资料,并向版主发送一封电子邮件。版主将登录 Django 管理站点,检查他们是否被允许注册并将其帐户标记为活动的。如果他们是一些试图溜进来的恶棍,该帐户将被删除。

我将使用 recaptcha 来尝试停止自动尝试。

我想在帐户被激活或删除时发送一封电子邮件,让帐户持有人知道他们的帐户发生了什么,他们可以登录,或者让他们知道我们知道他们在做什么,他们应该别傻了。

我怀疑这与信号有关,但坦率地说,鉴于我使用的是从django.contrib.auth.

任何提示、线索或代码都被亲切地接受。

4

2 回答 2

1
from django.db.models.signals import post_save
from django.contrib.auth.models import User

def send_user_email(sender, instance=None, **kwargs):
    if kwargs['created']:
        #your code here
post_save.connect(send_user_email, sender=User)

Something like this should work. Here are the docs.

于 2010-08-09T16:37:14.490 回答
1

You want to take a look at the Signals.

  • When the account is activated, you should use a pre_save. You can compare the current User with the existing instance at the database: check that the instance exists, check the previous was active=False, check that the new one is active=True, then send an email.
  • When the account is deleted, use a pre_delete. If you use a post_delete you won't be able to access to the email.
于 2010-08-09T16:38:11.697 回答