Example #1
0
    def save(self):
        user = super(AccountRegisterForm, self).save(commit=False)
        user.is_active = False
        user.save()

        profile = UserProfile(
            user=user,
            account_type=self.cleaned_data['account_type'],
        )
        profile.setup_activation_key()
        profile.save()

        # send email to user with activation link
        message = loader.render_to_string('account/account-activation-email.txt', {
            'protocol': 'http',
            'domain': Site.objects.get(id=SITE_ID).domain,
            'username': self.cleaned_data['username'],
            'activation_key': profile.activation_key,
        })
        mail_params = {
            'subject': _('SeeFitHappen Account Activation'),
            'message': message,
            'from_email': EMAIL_HOST_USER,
            'recipient_list': [self.cleaned_data['email']],
        }
        send_mail(**mail_params)

        return user
Example #2
0
    def test_account_activate_view_activation_days(self):
        user = User(username='******', password=self.user.password)
        user.save()

        user.date_joined = datetime.datetime.now(tz=pytz.utc) - datetime.timedelta(days=2)
        user.save()

        profile = UserProfile(user=user, account_type=AccountType.TRAINER)
        profile.setup_activation_key()
        profile.save()

        response = self.client.get(reverse('account.activate', args=[user.profile.activation_key]))
        self.assertEquals(response.status_code, 404)
Example #3
0
    def test_account_activate_view(self):
        user = User(username='******', password=self.user.password)
        user.save()

        profile = UserProfile(user=user, account_type=AccountType.TRAINER)
        profile.setup_activation_key()
        profile.save()

        user = User.objects.get(username='******')
        self.assertTrue(user.profile.activation_key)

        response = self.client.get(reverse('account.activate', args=[user.profile.activation_key]))
        self.assertEquals(response.status_code, 302)
        self.assertRedirects(response, reverse('account.activate.complete'))

        self.assertEquals(self.user.profile.activation_key, None)