@csrf_exempt
def unsubscribe_email(request, code, signed_token):
    ctx = {}
    if (':' in signed_token):
        signer = signing.TimestampSigner(salt='alerts')
        try:
            token = signer.unsign(signed_token)
        except signing.BadSignature:
            return render(request, 'bad_link.html')
        try:
            signer.unsign(signed_token, max_age=300)
        except signing.SignatureExpired:
            ctx['autosubmit'] = True
    else:
        token = signed_token
    channel = get_object_or_404(Channel, code=code, kind='email')
    if (channel.make_token() != token):
        return render(request, 'bad_link.html')
    if (request.method != 'POST'):
        return render(request, 'accounts/unsubscribe_submit.html', ctx)
    channel.delete()
    return render(request, 'front/unsubscribe_success.html')
@csrf_exempt
def unsubscribe_email(request, code, signed_token):
    ctx = {}
    if (':' in signed_token):
        signer = signing.TimestampSigner(salt='alerts')
        try:
            token = signer.unsign(signed_token)
        except signing.BadSignature:
            return render(request, 'bad_link.html')
        try:
            signer.unsign(signed_token, max_age=300)
        except signing.SignatureExpired:
            ctx['autosubmit'] = True
    else:
        token = signed_token
    channel = get_object_or_404(Channel, code=code, kind='email')
    if (channel.make_token() != token):
        return render(request, 'bad_link.html')
    if (request.method != 'POST'):
        return render(request, 'accounts/unsubscribe_submit.html', ctx)
    channel.delete()
    return render(request, 'front/unsubscribe_success.html')