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

anh*_*ran 12 django

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

Pho*_*beB 13

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

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

   (r'^accounts/', include('registration.backends.simple.urls')),    
Run Code Online (Sandbox Code Playgroud)


tee*_*ane 7

为什么不使用这种方法,只使用django-registration附带的简单后端而不是默认的后端?

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

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

url(r'^accounts/', include('registration.backends.default.urls')),
Run Code Online (Sandbox Code Playgroud)

url(r'^accounts/', include('registration.backends.simple.urls')),
Run Code Online (Sandbox Code Playgroud)


Lio*_*nel 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)
Run Code Online (Sandbox Code Playgroud)

然后,编辑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)
Run Code Online (Sandbox Code Playgroud)


Dom*_*ger 3

您始终可以将此行修改为:

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)
Run Code Online (Sandbox Code Playgroud)

或者您可以将此行更改为:

def create_inactive_user(self, username, password, email,
                         send_email=False, profile_callback=None):
Run Code Online (Sandbox Code Playgroud)

  • 不过,您需要调用 activate_user (否则用户的帐户将无法使用) (2认同)