How to disable email activation in django-registration app?

前端 未结 5 624
忘了有多久
忘了有多久 2020-12-05 01:04

How to disable email activation in django-registration app?

5条回答
  •  旧时难觅i
    2020-12-05 01:43

    Better to fix the problem at the root than bandage it by calling commands to automatically activate the user.

    Add this method to 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)
    

    Then, edit registration/backend/defaults/init.py and find the register() method.

    Change the following to call your new method:

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

提交回复
热议问题