Ejemplo n.º 1
0
    def _handle_set_is_active(self):
        state = bool(int(self.request.POST["set_is_active"]))
        if not state:
            if (getattr(self.object, 'is_superuser', False)
                    and not getattr(self.request.user, 'is_superuser', False)):
                raise Problem(
                    _("You can not deactivate a Superuser. Remove Superuser status first."
                      ))
            if self.object == self.request.user:
                raise Problem(
                    _("You can not deactivate yourself. Use another account."))

        if not self.object.is_active and state:
            user_reactivated.send(sender=self.__class__,
                                  user=self.object,
                                  request=self.request)

        self.object.is_active = state
        self.object.save(update_fields=("is_active", ))

        if hasattr(self.object, "contact"):
            self.object.contact.is_active = state
            self.object.contact.save(update_fields=("is_active", ))

        messages.success(
            self.request,
            _("%(user)s is now %(state)s.") % {
                "user": self.object,
                "state": _("active") if state else _("inactive")
            })
        return HttpResponseRedirect(self.request.path)
Ejemplo n.º 2
0
def test_account_reactivation_mail(client):
    shop = get_default_shop()
    Script.objects.create(
        event_identifier="account_reactivation",
        name="Send account reactivation email",
        enabled=True,
        shop=shop,
        template="account_reactivated",
        _step_data=[
            {
                "conditions": [],
                "actions": [
                    {
                        "identifier": "send_email",
                        "template_data": {
                            "base": {"content_type": "html", "subject": "", "body": ""},
                            "en": {
                                "content_type": "html",
                                "subject": "Welcome back {{ customer.name }}",
                                "body": "<p>Hello your account is now active again <code>{{ customer_email }}</code></p>",
                            },
                        },
                        "language": {"variable": "language"},
                        "fallback_language": {"constant": "en"},
                        "recipient": {"variable": "customer_email"},
                    }
                ],
                "next": "stop",
                "cond_op": "all",
                "enabled": True,
            }
        ],
    )

    response = client.post(
        reverse("shuup:registration_register"),
        data={
            "username": username,
            "email": email,
            "password1": "password",
            "password2": "password",
        },
        follow=True,
    )
    response.shop = shop

    user = get_user_model().objects.get(username=username)
    mail.outbox = []

    user_reactivated.send(sender=__name__, user=user, request=response)

    reActivMail = mail.outbox[0]
    customer = get_person_contact(user)
    assert reActivMail.subject == "Welcome back " + customer.name
    assert reActivMail.body == ("<p>Hello your account is now active again <code>" + customer.email + "</code></p>")
    assert reActivMail.to[0] == customer.email