Exemplo n.º 1
0
def send_activation(request,
                    user_id,
                    template_name='im/login.html',
                    extra_context=None):

    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))

    extra_context = extra_context or {}
    try:
        u = AstakosUser.objects.select_for_update().get(id=user_id)
    except AstakosUser.DoesNotExist:
        messages.error(request, _(astakos_messages.ACCOUNT_UNKNOWN))
    else:
        if u.email_verified:
            logger.warning("[resend activation] Account already verified: %s",
                           u.log_display)

            messages.error(request,
                           _(astakos_messages.ACCOUNT_ALREADY_VERIFIED))
        else:
            user_logic.send_verification_mail(u)
            messages.success(request, astakos_messages.ACTIVATION_SENT)

    return HttpResponseRedirect(reverse('index'))
Exemplo n.º 2
0
    def test_verification_mail(self):
        """Test if verification mails are sent correctly."""
        # Check if we can send a verification mail to an unverified user.
        ok, _ = validate_user_action(self.user1, "SEND_VERIFICATION_MAIL")
        self.assertTrue(ok)
        send_verification_mail(self.user1)

        # Check if any mail has been sent and if so, check if it has two
        # important properties: the user's realname and his/her verification
        # code
        self.assertEqual(len(mail.outbox), 1)
        body = mail.outbox[0].body
        self.assertIn(self.user1.realname, body)
        self.assertIn(self.user1.verification_code, body)

        # Verify the user.
        res = verify(self.user1, self.user1.verification_code)
        self.assertFalse(res.is_error())

        # Check if we are prevented from sending a verification mail.
        ok, _ = validate_user_action(self.user1, "SEND_VERIFICATION_MAIL")
        self.assertFalse(ok)
        with self.assertRaises(Exception) as cm:
            send_verification_mail(self.user1)
        self.assertEqual(cm.exception.message, "User email already verified.")
Exemplo n.º 3
0
    def test_verification_mail(self):
        """Test if verification mails are sent correctly."""
        # Check if we can send a verification mail to an unverified user.
        ok, _ = validate_user_action(self.user1, "SEND_VERIFICATION_MAIL")
        self.assertTrue(ok)
        send_verification_mail(self.user1)

        # Check if any mail has been sent and if so, check if it has two
        # important properties: the user's realname and his/her verification
        # code
        self.assertEqual(len(mail.outbox), 1)
        body = mail.outbox[0].body
        self.assertIn(self.user1.realname, body)
        self.assertIn(self.user1.verification_code, body)

        # Verify the user.
        res = verify(self.user1, self.user1.verification_code)
        self.assertFalse(res.is_error())

        # Check if we are prevented from sending a verification mail.
        ok, _ = validate_user_action(self.user1, "SEND_VERIFICATION_MAIL")
        self.assertFalse(ok)
        with self.assertRaises(Exception) as cm:
            send_verification_mail(self.user1)
        self.assertEqual(cm.exception.message, "User email already verified.")
Exemplo n.º 4
0
    def handle(self, *args, **options):
        if not args:
            raise CommandError("No user was given")

        for email_or_id in args:
            user = get_user(email_or_id)
            if not user:
                self.stderr.write("Unknown user '%s'\n" % (email_or_id, ))
                continue
            if user.email_verified:
                self.stderr.write("User email already verified '%s'\n" %
                                  (user.email, ))
                continue

            send_verification_mail(user)

            self.stderr.write("Activation sent to '%s'\n" % (user.email, ))
Exemplo n.º 5
0
    def handle(self, *args, **options):
        if not args:
            raise CommandError("No user was given")

        for email_or_id in args:
            user = get_user(email_or_id)
            if not user:
                self.stderr.write("Unknown user '%s'\n" % (email_or_id,))
                continue
            if user.email_verified:
                self.stderr.write(
                    "User email already verified '%s'\n" % (user.email,))
                continue

            send_verification_mail(user)

            self.stderr.write("Activation sent to '%s'\n" % (user.email,))
Exemplo n.º 6
0
Arquivo: im.py Projeto: grnet/synnefo
def send_activation(request, user_id, template_name='im/login.html',
                    extra_context=None):

    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))

    extra_context = extra_context or {}
    try:
        u = AstakosUser.objects.select_for_update().get(id=user_id)
    except AstakosUser.DoesNotExist:
        messages.error(request, _(astakos_messages.ACCOUNT_UNKNOWN))
    else:
        if u.email_verified:
            logger.warning("[resend activation] Account already verified: %s",
                           u.log_display)

            messages.error(request,
                           _(astakos_messages.ACCOUNT_ALREADY_VERIFIED))
        else:
            user_logic.send_verification_mail(u)
            messages.success(request, astakos_messages.ACTIVATION_SENT)

    return HttpResponseRedirect(reverse('index'))