Beispiel #1
0
def confirm(request, token):
    """
    Confirm subscriptions.
    """
    success = generic_error = token_error = False

    try:
        result = basket.confirm(token)
    except basket.BasketException as e:
        log.exception("Exception confirming token %s" % token)
        if e.code == basket.errors.BASKET_UNKNOWN_TOKEN:
            token_error = True
        else:
            # Any other exception
            generic_error = True
    else:
        if result['status'] == 'ok':
            success = True
        else:
            # Shouldn't happen (errors should raise exception),
            # but just in case:
            generic_error = True

    return l10n_utils.render(
        request,
        'newsletter/confirm.html',
        {'success': success,
         'generic_error': generic_error,
         'token_error': token_error})
Beispiel #2
0
def confirm(request, token):
    """
    Confirm subscriptions.
    """
    success = generic_error = token_error = False

    try:
        result = basket.confirm(token)
    except basket.BasketException as e:
        log.exception("Exception confirming token %s" % token)
        if e.code == basket.errors.BASKET_UNKNOWN_TOKEN:
            token_error = True
        else:
            # Any other exception
            generic_error = True
    else:
        if result['status'] == 'ok':
            success = True
        else:
            # Shouldn't happen (errors should raise exception),
            # but just in case:
            generic_error = True

    return l10n_utils.render(
        request,
        'newsletter/confirm.html',
        {'success': success,
         'generic_error': generic_error,
         'token_error': token_error})
Beispiel #3
0
 def test_confirm(self):
     """
     confirm() passes the expected args to request, and returns the result.
     """
     token = "TOKEN"
     with patch('basket.base.request', autospec=True) as request_call:
         result = confirm(token)
     request_call.assert_called_with('post', 'confirm', token=token)
     self.assertEqual(request_call.return_value, result)
Beispiel #4
0
 def test_confirm(self):
     """
     confirm() passes the expected args to request, and returns the result.
     """
     token = "TOKEN"
     with patch('basket.base.request', autospec=True) as request_call:
         result = confirm(token)
     request_call.assert_called_with('post', 'confirm', token=token)
     self.assertEqual(request_call.return_value, result)
Beispiel #5
0
def confirm(request, token):
    """
    Confirm subscriptions.
    """
    success = generic_error = token_error = rate_limit_error = False

    try:
        result = basket.confirm(token)
    except basket.BasketException as e:
        log.exception(f"Exception confirming token {token}")
        if e.code == basket.errors.BASKET_UNKNOWN_TOKEN:
            token_error = True
        elif e.code == basket.errors.BASKET_USAGE_ERROR:
            rate_limit_error = True
        else:
            # Any other exception
            generic_error = True
    else:
        if result["status"] == "ok":
            success = True
        else:
            # Shouldn't happen (errors should raise exception),
            # but just in case:
            generic_error = True

    # Assume rate limit error means user already confirmed and clicked confirm
    # link twice in quick succession
    if success or rate_limit_error:
        qparams = ["confirm=1"]
        qs = request.META.get("QUERY_STRING", "")
        if qs:
            qparams.append(qs)
        return HttpResponseRedirect("{}?{}".format(
            reverse("newsletter.existing.token", kwargs={"token": token}),
            "&".join(qparams)))
    else:
        return l10n_utils.render(request,
                                 "newsletter/confirm.html", {
                                     "success": success,
                                     "generic_error": generic_error,
                                     "token_error": token_error
                                 },
                                 ftl_files=FTL_FILES)
Beispiel #6
0
def confirm(request, token):
    """
    Confirm subscriptions.
    """
    success = generic_error = token_error = rate_limit_error = False

    try:
        result = basket.confirm(token)
    except basket.BasketException as e:
        log.exception("Exception confirming token %s" % token)
        if e.code == basket.errors.BASKET_UNKNOWN_TOKEN:
            token_error = True
        elif e.code == basket.errors.BASKET_USAGE_ERROR:
            rate_limit_error = True
        else:
            # Any other exception
            generic_error = True
    else:
        if result['status'] == 'ok':
            success = True
        else:
            # Shouldn't happen (errors should raise exception),
            # but just in case:
            generic_error = True

    # Assume rate limit error means user already confirmed and clicked confirm
    # link twice in quick succession
    if success or rate_limit_error:
        qparams = ['confirm=1']
        qs = request.META.get('QUERY_STRING', '')
        if qs:
            qparams.append(qs)
        return HttpResponseRedirect(
            "%s?%s" % (reverse('newsletter.existing.token',
                               kwargs={'token': token}), '&'.join(qparams)))
    else:
        return l10n_utils.render(request,
                                 'newsletter/confirm.html', {
                                     'success': success,
                                     'generic_error': generic_error,
                                     'token_error': token_error
                                 },
                                 ftl_files=FTL_FILES)
Beispiel #7
0
def confirm(request, token):
    """
    Confirm subscriptions.
    """
    success = generic_error = token_error = rate_limit_error = False

    try:
        result = basket.confirm(token)
    except basket.BasketException as e:
        log.exception("Exception confirming token %s" % token)
        if e.code == basket.errors.BASKET_UNKNOWN_TOKEN:
            token_error = True
        elif e.code == basket.errors.BASKET_USAGE_ERROR:
            rate_limit_error = True
        else:
            # Any other exception
            generic_error = True
    else:
        if result['status'] == 'ok':
            success = True
        else:
            # Shouldn't happen (errors should raise exception),
            # but just in case:
            generic_error = True

    # Assume rate limit error means user already confirmed and clicked confirm
    # link twice in quick succession
    if success or rate_limit_error:
        qparams = ['confirm=1']
        qs = request.META.get('QUERY_STRING', '')
        if qs:
            qparams.append(qs)
        return HttpResponseRedirect("%s?%s" % (reverse('newsletter.existing.token',
                                                       kwargs={'token': token}),
                                               '&'.join(qparams)))
    else:
        return l10n_utils.render(
            request,
            'newsletter/confirm.html',
            {'success': success,
             'generic_error': generic_error,
             'token_error': token_error})