Пример #1
0
def billing_notify():
    billing_check()

    limit = Billing.objects.get_out_of_limits()
    due = Billing.objects.get_unpaid()

    with_project = Billing.objects.annotate(Count("projects")).filter(
        projects__count__gt=0
    )
    toremove = with_project.exclude(removal=None).order_by("removal")
    trial = with_project.filter(removal=None, state=Billing.STATE_TRIAL).order_by(
        "expiry"
    )

    if limit or due or toremove or trial:
        send_notification_email(
            "en",
            [a[1] for a in settings.ADMINS] + settings.ADMINS_BILLING,
            "billing_check",
            context={
                "limit": limit,
                "due": due,
                "toremove": toremove,
                "trial": trial,
            },
        )
Пример #2
0
def send_validation(strategy, backend, code, partial_token):
    """Send verification e-mail."""
    # We need to have existing session
    session = strategy.request.session
    if not session.session_key:
        session.create()
    session["registration-email-sent"] = True

    url = "{}?verification_code={}&partial_token={}".format(
        reverse("social:complete", args=(backend.name, )), code.code,
        partial_token)

    context = {"url": url, "validity": settings.AUTH_TOKEN_VALID // 3600}

    template = "activation"
    if session.get("password_reset"):
        template = "reset"
    elif session.get("account_remove"):
        template = "remove"
    elif session.get("user_invite"):
        template = "invite"
        context.update(session["invitation_context"])

    send_notification_email(None, [code.email],
                            template,
                            info=url,
                            context=context)
Пример #3
0
def send_validation(strategy, backend, code, partial_token):
    """Send verification email."""
    # We need to have existing session
    if not strategy.request.session.session_key:
        strategy.request.session.create()
    strategy.request.session['registration-email-sent'] = True

    template = 'activation'
    if strategy.request.session.get('password_reset'):
        template = 'reset'
    elif strategy.request.session.get('account_remove'):
        template = 'remove'

    url = '{0}?verification_code={1}&partial_token={2}'.format(
        reverse('social:complete', args=(backend.name,)),
        code.code,
        partial_token,
    )

    send_notification_email(
        None,
        code.email,
        template,
        info=url,
        context={
            'url': url
        }
    )
Пример #4
0
def reset_password(request):
    """Password reset handling."""
    if request.user.is_authenticated:
        return redirect_profile()
    if "email" not in get_auth_keys():
        messages.error(
            request,
            _("Cannot reset password, e-mail authentication is turned off."))
        return redirect("login")

    captcha = None

    # We're already in the reset phase
    if "perform_reset" in request.session:
        return reset_password_set(request)
    if request.method == "POST":
        form = ResetForm(request.POST)
        if settings.REGISTRATION_CAPTCHA:
            captcha = CaptchaForm(request, form, request.POST)
        if (captcha is None or captcha.is_valid()) and form.is_valid():
            if form.cleaned_data["email_user"]:
                audit = AuditLog.objects.create(
                    form.cleaned_data["email_user"], request, "reset-request")
                if not audit.check_rate_limit(request):
                    store_userid(request, True)
                    return social_complete(request, "email")
            else:
                email = form.cleaned_data["email"]
                send_notification_email(
                    None,
                    [email],
                    "reset-nonexisting",
                    context={
                        "address": get_ip_address(request),
                        "user_agent:": get_user_agent(request),
                        "registration_hint": get_registration_hint(email),
                    },
                )
            return fake_email_sent(request, True)
    else:
        form = ResetForm()
        if settings.REGISTRATION_CAPTCHA:
            captcha = CaptchaForm(request)

    return render(
        request,
        "accounts/reset.html",
        {
            "title": _("Password reset"),
            "form": form,
            "captcha_form": captcha,
            "second_stage": False,
        },
    )
Пример #5
0
def billing_notify():
    billing_check()

    limit = Billing.objects.get_out_of_limits()
    due = Billing.objects.get_unpaid()

    if limit or due:
        send_notification_email(
            'en', 'ADMINS', 'billing_check',
            context={'limit': limit, 'due': due}
        )
Пример #6
0
def billing_notify():
    billing_check()

    limit = Billing.objects.get_out_of_limits()
    due = Billing.objects.get_unpaid()

    if limit or due:
        send_notification_email(
            'en', 'ADMINS', 'billing_check',
            context={'limit': limit, 'due': due}
        )
Пример #7
0
def billing_notify():
    billing_check()

    limit = Billing.objects.get_out_of_limits()
    due = Billing.objects.get_unpaid()

    if limit or due:
        send_notification_email(
            "en",
            [a[1] for a in settings.ADMINS] + settings.ADMINS_BILLING,
            "billing_check",
            context={"limit": limit, "due": due},
        )
Пример #8
0
def billing_notify():
    billing_check()

    limit = Billing.objects.get_out_of_limits()
    due = Billing.objects.get_unpaid()
    toremove = Billing.objects.exclude(removal=None).order_by("removal")

    if limit or due or toremove:
        send_notification_email(
            "en",
            [a[1] for a in settings.ADMINS] + settings.ADMINS_BILLING,
            "billing_check",
            context={"limit": limit, "due": due, "toremove": toremove},
        )
Пример #9
0
def billing_notify():
    billing_check()

    limit = Billing.objects.get_out_of_limits()
    due = Billing.objects.get_unpaid()

    if limit or due:
        send_notification_email(
            'en',
            [a[1] for a in settings.ADMINS] + settings.ADMINS_BILLING,
            'billing_check',
            context={
                'limit': limit,
                'due': due
            },
        )
Пример #10
0
def notify_auditlog(log_id):
    from weblate.accounts.models import AuditLog
    from weblate.accounts.notifications import send_notification_email
    audit = AuditLog.objects.get(pk=log_id)
    send_notification_email(
        audit.user.profile.language,
        audit.user.email,
        'account_activity',
        context={
            'message': audit.get_message,
            'extra_message': audit.get_extra_message,
            'address': audit.address,
            'user_agent': audit.user_agent,
        },
        info='{0} from {1}'.format(audit.activity, audit.address),
    )
Пример #11
0
def perform_removal():
    for bill in Billing.objects.filter(removal__lte=timezone.now()):
        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                [user.email],
                "billing_expired",
                context={"billing": bill, "final_removal": True},
                info=bill,
            )
        for prj in bill.projects.iterator():
            prj.log_warning("removing due to unpaid billing")
            prj.stats.invalidate()
            prj.delete()
        bill.removal = None
        bill.state = Billing.STATE_TERMINATED
        bill.save()
Пример #12
0
def notify_auditlog(log_id, email):
    from weblate.accounts.models import AuditLog
    from weblate.accounts.notifications import send_notification_email

    audit = AuditLog.objects.get(pk=log_id)
    send_notification_email(
        audit.user.profile.language,
        [email],
        "account_activity",
        context={
            "message": audit.get_message,
            "extra_message": audit.get_extra_message,
            "address": audit.address,
            "user_agent": audit.user_agent,
        },
        info="{0} from {1}".format(audit.activity, audit.address),
    )
Пример #13
0
def trial(request):
    """Form for hosting request."""
    if not settings.OFFER_HOSTING:
        return redirect("home")

    plan = request.POST.get("plan", "enterprise")

    # Avoid frequent requests for a trial for same user
    if plan != "libre" and request.user.auditlog_set.filter(
            activity="trial").exists():
        messages.error(
            request,
            _("Seems you've already requested a trial period recently. "
              "Please contact us with your inquiry so we can find the "
              "best solution for you."),
        )
        return redirect(reverse("contact") + "?t=trial")

    if request.method == "POST":
        from weblate.billing.models import Billing, Plan

        billing = Billing.objects.create(
            plan=Plan.objects.get(slug=plan),
            state=Billing.STATE_TRIAL,
            expiry=timezone.now() + timedelta(days=14),
        )
        billing.owners.add(request.user)
        AuditLog.objects.create(request.user, request, "trial")
        send_notification_email(
            "en",
            [a[1] for a in settings.ADMINS] + settings.ADMINS_BILLING,
            "new_trial",
            context={
                "user": request.user,
                "billing": billing
            },
        )
        messages.info(
            request,
            _("Your trial period is now up and running; "
              "create your translation project and start Weblating!"),
        )
        return redirect(reverse("create-project") + f"?billing={billing.pk}")

    return render(request, "accounts/trial.html", {"title": _("Gratis trial")})
Пример #14
0
def notify_expired():
    possible_billings = Billing.objects.filter(
        Q(state=Billing.STATE_ACTIVE) | Q(removal__isnull=False))
    for bill in possible_billings:
        if bill.state != Billing.STATE_TRIAL and bill.check_payment_status():
            continue

        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                user.email,
                'billing_expired',
                context={
                    'billing': bill,
                    'billing_url': get_site_url(reverse('billing')),
                },
                info=bill,
            )
Пример #15
0
def notify_expired():
    for bill in Billing.objects.filter(state=Billing.STATE_ACTIVE):
        if bill.check_payment_status():
            continue
        users = bill.owners.distinct()
        for project in bill.projects.all():
            users |= User.objects.having_perm('billing.view', project)

        for user in users:
            send_notification_email(
                user.profile.language,
                user.email,
                'billing_expired',
                context={
                    'billing': bill,
                    'billing_url': get_site_url(reverse('billing')),
                },
                info=bill,
            )
Пример #16
0
def notify_expired():
    for bill in Billing.objects.filter(state=Billing.STATE_ACTIVE):
        if bill.check_payment_status():
            continue
        users = bill.owners.distinct()
        for project in bill.projects.all():
            users |= User.objects.having_perm('billing.view', project)

        for user in users:
            send_notification_email(
                user.profile.language,
                user.email,
                'billing_expired',
                context={
                    'billing': bill,
                    'billing_url': get_site_url(reverse('billing')),
                },
                info=bill,
            )
Пример #17
0
def notify_expired():
    possible_billings = Billing.objects.filter(
        Q(state=Billing.STATE_ACTIVE) | Q(removal__isnull=False)
    )
    for bill in possible_billings:
        if bill.state != Billing.STATE_TRIAL and bill.check_payment_status():
            continue

        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                user.email,
                'billing_expired',
                context={
                    'billing': bill,
                    'billing_url': get_site_url(reverse('billing')),
                },
                info=bill,
            )
Пример #18
0
def perform_removal():
    for bill in Billing.objects.filter(removal__lte=timezone.now()):
        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                user.email,
                'billing_expired',
                context={
                    'billing': bill,
                    'billing_url': get_site_url(reverse('billing')),
                    'final_removal': True,
                },
                info=bill,
            )
        for prj in bill.projects.iterator():
            prj.log_warning('removing due to unpaid billing')
            prj.stats.invalidate()
            prj.delete()
        bill.removal = None
        bill.state = Billing.STATE_TERMINATED
        bill.save()
Пример #19
0
def perform_removal():
    for bill in Billing.objects.filter(removal__lte=timezone.now()):
        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                user.email,
                'billing_expired',
                context={
                    'billing': bill,
                    'billing_url': get_site_url(reverse('billing')),
                    'final_removal': True,
                },
                info=bill,
            )
        for prj in bill.projects.iterator():
            prj.log_warning('removing due to unpaid billing')
            prj.stats.invalidate()
            prj.delete()
        bill.removal = None
        bill.state = Billing.STATE_TERMINATED
        bill.save()
Пример #20
0
def send_validation(strategy, backend, code, partial_token=None):
    """Send verification email."""

    # We need to have existing session
    if not strategy.request.session.session_key:
        strategy.request.session.create()

    template = 'activation'
    if strategy.request.session.pop('password_reset', False):
        template = 'reset'

    url = '{0}?verification_code={1}&id={2}&type={3}'.format(
        reverse('social:complete', args=(backend.name, )), code.code,
        strategy.request.session.session_key, template)
    if partial_token:
        url += '&partial_token={0}'.format(partial_token)

    send_notification_email(None,
                            code.email,
                            template,
                            info=url,
                            context={'url': url})
Пример #21
0
def trial_expired():
    billings = Billing.objects.filter(
        state=Billing.STATE_TRIAL,
        expiry__lte=timezone.now() +
        timedelta(days=7)).exclude(projects__isnull=True)
    for bill in billings:
        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                [user.email],
                "billing_expired",
                context={
                    "billing":
                    bill,
                    "payment_enabled":
                    getattr(settings, "PAYMENT_ENABLED", False),
                    "unsubscribe_note":
                    _("You will stop receiving this notification once "
                      "you change to regular subscription or the project is removed."
                      ),
                },
                info=bill,
            )
Пример #22
0
def notify_expired():
    possible_billings = Billing.objects.filter(
        Q(state=Billing.STATE_ACTIVE) | Q(removal__isnull=False)
    ).exclude(projects__isnull=True)
    for bill in possible_billings:
        if bill.state != Billing.STATE_TRIAL and bill.check_payment_status():
            continue

        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                [user.email],
                "billing_expired",
                context={
                    "billing": bill,
                    "payment_enabled": getattr(settings, "PAYMENT_ENABLED", False),
                    "unsubscribe_note": _(
                        "You will stop receiving this notification once "
                        "you pay the bills or the project is removed."
                    ),
                },
                info=bill,
            )
Пример #23
0
def notify_expired():
    # Notify about expired billings
    possible_billings = Billing.objects.filter(
        # Active without payment (checked later)
        Q(state=Billing.STATE_ACTIVE)
        # Scheduled removal
        | Q(removal__isnull=False)
        # Trials expiring soon
        | Q(state=Billing.STATE_TRIAL,
            expiry__lte=timezone.now() + timedelta(days=7))).exclude(
                projects__isnull=True)
    for bill in possible_billings:
        if bill.state == Billing.STATE_ACTIVE and bill.check_payment_status(
                now=True):
            continue
        if bill.plan.price:
            note = _("You will stop receiving this notification once "
                     "you pay the bills or the project is removed.")
        else:
            note = _(
                "You will stop receiving this notification once "
                "you change to regular subscription or the project is removed."
            )

        for user in bill.get_notify_users():
            send_notification_email(
                user.profile.language,
                [user.email],
                "billing_expired",
                context={
                    "billing": bill,
                    "payment_enabled": getattr(settings, "PAYMENT_ENABLED",
                                               False),
                    "unsubscribe_note": note,
                },
                info=bill,
            )
Пример #24
0
def send_validation(strategy, backend, code, partial_token):
    """Send verification e-mail."""
    # We need to have existing session
    session = strategy.request.session
    if not session.session_key:
        session.create()
    session['registration-email-sent'] = True

    url = '{0}?verification_code={1}&partial_token={2}'.format(
        reverse('social:complete', args=(backend.name,)), code.code, partial_token
    )

    context = {'url': url, 'validity': settings.AUTH_TOKEN_VALID // 3600}

    template = 'activation'
    if session.get('password_reset'):
        template = 'reset'
    elif session.get('account_remove'):
        template = 'remove'
    elif session.get('user_invite'):
        template = 'invite'
        context.update(session['invitation_context'])

    send_notification_email(None, [code.email], template, info=url, context=context)