summaryrefslogtreecommitdiff
path: root/talerblog/blog/blog.py
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-08-24 12:50:36 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-08-24 12:50:36 +0200
commitb13964c84195df8535bc1740da50e96450c6d888 (patch)
treec85696e9d5ba775505f3878737f52bcd19d87a1c /talerblog/blog/blog.py
parentc36aa82a089a9da7aaca3655ae1f96e82348c0e1 (diff)
downloadblog-b13964c84195df8535bc1740da50e96450c6d888.tar.gz
blog-b13964c84195df8535bc1740da50e96450c6d888.tar.bz2
blog-b13964c84195df8535bc1740da50e96450c6d888.zip
qrcode support
Diffstat (limited to 'talerblog/blog/blog.py')
-rw-r--r--talerblog/blog/blog.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/talerblog/blog/blog.py b/talerblog/blog/blog.py
index 6f09852..e35dd0e 100644
--- a/talerblog/blog/blog.py
+++ b/talerblog/blog/blog.py
@@ -17,14 +17,17 @@
# @author Marcello Stanisci
# @brief Implementation of a Taler-compatible blog.
-from urllib.parse import urljoin, quote
+from urllib.parse import urljoin, quote, urlencode
import logging
import os
import traceback
import uuid
+import qrcode
+import qrcode.image.svg
import base64
import requests
import flask
+import lxml.etree
from cachelib import UWSGICache, SimpleCache
from talerblog.talerconfig import TalerConfig
from ..blog.content import ARTICLES, get_article_file, get_image_file
@@ -224,6 +227,10 @@ def render_article(article_name, data, order_id):
article_name=article_name,
order_id=order_id)
+def get_qrcode_svg(data):
+ factory = qrcode.image.svg.SvgImage
+ img = qrcode.make(data, image_factory=factory)
+ return lxml.etree.tostring(img.get_image())
##
# Trigger a article purchase. The logic follows the main steps:
@@ -281,10 +288,16 @@ def article(article_name, data=None):
order_id = order_resp["order_id"]
##
+ # The resource URL uniquely identifies the Web resource that
+ # the customer is paying for, and is used to detect that an
+ # article has already been puchased when the cookie was lost.
+ resource_url = flask.request.base_url
+
+ ##
# Prepare data for the upcoming payment check.
pay_params = dict(instance=INSTANCE,
order_id=order_id,
- resource_url=flask.request.base_url,
+ resource_url=resource_url,
session_id=session_id,
session_sig=session_sig)
@@ -316,9 +329,17 @@ def article(article_name, data=None):
# Redirect the browser to a page where the wallet can
# run the payment protocol.
contract_url = pay_status["contract_url"]
- headers = {"X-Taler-Contract-Url": contract_url}
+ headers = {
+ "X-Taler-Contract-Url": contract_url,
+ "X-Taler-Session-Url": session_id,
+ "X-Taler-Resource-Url": resource_url,
+ }
+
+ qrcode_data = "talerpay:" + urlencode(contract_url) + ";" + session_id
+ qrcode_svg = get_qrcode_svg(qrcode_data)
content = flask.render_template("templates/request_payment.html",
- article_name=article_name)
+ article_name=article_name,
+ qrcode_svg=qrcode_svg)
resp = flask.Response(content, status=402, headers=headers)
return resp