def test_user_creation_no_email(self): '''Passing ``send_email=False`` when creating a new user will not send an activation email. ''' site = Site.get_current() RegistrationProfile.create_inactive_user(send_email=False, site=site, **self.user_info) self.assertEqual(len(mail.outbox), 0)
def register(self, request, **kwargs): """Given a username, email address and password, register a new user account, which will initially be inactive. Along with the new ``User`` object, a new ``registration.models.RegistrationProfile`` will be created, tied to that ``User``, containing the activation key which will be used for this account. An email will be sent to the supplied email address; this email should contain an activation link. The email will be rendered using two templates. See the documentation for ``RegistrationProfile.send_activation_email()`` for information about these templates and the contexts provided to them. After the ``User`` and ``RegistrationProfile`` are created and the activation email is sent, the signal ``registration.signals.user_registered`` will be sent, with the new ``User`` as the keyword argument ``user`` and the class of this backend as the sender. """ username, email, password = (kwargs["username"], kwargs["email"], kwargs["password1"]) site = get_current_site(request) new_user = RegistrationProfile.create_inactive_user(username, email, password, site) signals.user_registered.send(sender=self.__class__, user=new_user, request=request) return new_user
def register(self, request, **kwargs): '''Given a username, email address and password, register a new user account, which will initially be inactive. Along with the new ``User`` object, a new ``registration.models.RegistrationProfile`` will be created, tied to that ``User``, containing the activation key which will be used for this account. An email will be sent to the supplied email address; this email should contain an activation link. The email will be rendered using two templates. See the documentation for ``RegistrationProfile.send_activation_email()`` for information about these templates and the contexts provided to them. After the ``User`` and ``RegistrationProfile`` are created and the activation email is sent, the signal ``registration.signals.user_registered`` will be sent, with the new ``User`` as the keyword argument ``user`` and the class of this backend as the sender. ''' username, email, password = (kwargs['username'], kwargs['email'], kwargs['password1']) site = get_current_site(request) new_user = RegistrationProfile.create_inactive_user(username, email, password, site) signals.user_registered.send(sender=self.__class__, user=new_user, request=request) return new_user
def test_management_command(self): '''The ``cleanupregistration`` management command properly deletes expired accounts. ''' site = Site.get_current() self.create_inactive_user() expired_user = \ RegistrationProfile.create_inactive_user(username='******', password='******', email='*****@*****.**', session=self.session, site=site) expired_user.date_joined -= \ timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1) self.session.commit() management.call_command('cleanupregistration') ct = self.session.query(RegistrationProfile).count() self.assertEqual(ct, 1) user_count = self.session.query(User) \ .filter_by(username=u'bob') \ .count() self.assertEqual(user_count, 0)
def test_expired_user_deletion(self): ''':meth:`RegistrationProfile.delete_expired_users` only deletes inactive users whose activation window has expired. ''' site = Site.get_current() self.create_inactive_user() expired_user = \ RegistrationProfile.create_inactive_user(username='******', password='******', email='*****@*****.**', session=self.session, site=site) expired_user.date_joined -= \ timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS + 1) self.session.commit() RegistrationProfile.delete_expired_users() ct = self.session.query(RegistrationProfile).count() self.assertEqual(ct, 1) user_count = self.session.query(User) \ .filter_by(username=u'bob') \ .count() self.assertEqual(user_count, 0)
def create_inactive_user(self): site = Site.get_current() return RegistrationProfile.create_inactive_user(site=site, **self.user_info)