如何在django-registration app中禁用电子邮件激活?

时间:2009-12-03 09:21:47

标签: django

如何在django-registration app中禁用电子邮件激活?

5 个答案:

答案 0 :(得分:13)

在django-registration的当前提示版本中,有一个没有电子邮件的简单后端,您可以编写自己的后端来指定所需的工作流程。有关文档,请参见此处https://bitbucket.org/ubernostrum/django-registration/src/fad7080fe769/docs/backend-api.rst

要在没有电子邮件的情况下使用简单的,只需将您的urls.py更改为指向此后端,例如。

   (r'^accounts/', include('registration.backends.simple.urls')),    

答案 1 :(得分:7)

为什么不使用this method而只使用django-registration附带的简单后端而不是默认的后端?

新的工作流程将是...... 1.用户通过填写​​注册表格进行注册。 2.用户的帐户已创建并立即生效,没有中间确认或激活步骤。 3.新用户立即登录。

所以在您的主urls.py上你会改变:

url(r'^accounts/', include('registration.backends.default.urls')),

url(r'^accounts/', include('registration.backends.simple.urls')),

答案 2 :(得分:6)

最好通过调用命令来自动激活用户来解决根本问题而不是绷带。

将此方法添加到registration models.py:

   def create_active_user(self, username, email, password,
                             site):
        """
        Create a new, active ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.
        """
        new_user = User.objects.create_user(username, email, password)
        new_user.is_active = True
        new_user.save()

        registration_profile = self.create_profile(new_user)

        return new_user
    create_active_user = transaction.commit_on_success(create_active_user)

然后,编辑registration / backend / defaults / init .py并找到register()方法。

更改以下内容以调用新方法:

#new_user = RegistrationProfile.objects.create_inactive_user(username, email,
                                                            #password, site)
new_user = RegistrationProfile.objects.create_active_user(username, email,
                                                            password, site)

答案 3 :(得分:3)

您可以随时将this line修改为:

new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
                                       password=self.cleaned_data['password1'],
                                       email=self.cleaned_data['email'],
                                       profile_callback=profile_callback,
                                       send_email = False)

或者您可以将this line更改为:

def create_inactive_user(self, username, password, email,
                         send_email=False, profile_callback=None):

答案 4 :(得分:1)

为什么不激活用户same way django-registration does

,而不是修改注册应用程序 <德尔>     user.is_active = True     user.save()     profile.activation_key =“ALREADY_ACTIVATED”     profile.save()    

看了更多......我想你想要的是两种解决方案。可能在Dominic建议的更改之后添加上面的代码(尽管我建议使用信号,或者如果可能的话继承子表单)

好的最终答案:

new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
                                   password=self.cleaned_data['password1'],
                                   email=self.cleaned_data['email'],
                                   profile_callback=profile_callback,
                                   send_email = False)
RegistrationProfile.objects.activate_user(new_user.activation_key)