diff options
author | Sebastian <sebasjm@gmail.com> | 2024-02-07 09:21:22 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-02-07 09:21:22 -0300 |
commit | 0c629825b47f3b5e90b85f534b03bbb9d3e9c383 (patch) | |
tree | 57c6c46094c80087082224636310054bfea56993 | |
parent | 8f7e0cbd33c423970806331e6a4d6b553a55db5b (diff) | |
download | taler-merchant-demos-0c629825b47f3b5e90b85f534b03bbb9d3e9c383.tar.gz taler-merchant-demos-0c629825b47f3b5e90b85f534b03bbb9d3e9c383.tar.bz2 taler-merchant-demos-0c629825b47f3b5e90b85f534b03bbb9d3e9c383.zip |
fix #8326
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rwxr-xr-x | debian/rules | 1 | ||||
-rw-r--r-- | debian/taler-merchant-demos.taler-demo-survey.service | 12 | ||||
-rw-r--r-- | pyproject.toml | 5 | ||||
-rw-r--r-- | taler.conf | 14 | ||||
-rw-r--r-- | talermerchantdemos/cli.py | 6 | ||||
-rw-r--r-- | talermerchantdemos/landing/landing.py | 6 | ||||
-rw-r--r-- | talermerchantdemos/survey/__init__.py | 3 | ||||
-rw-r--r-- | talermerchantdemos/survey/survey.py | 225 | ||||
-rw-r--r-- | talermerchantdemos/templates/common-base.html.j2 | 3 | ||||
-rw-r--r-- | talermerchantdemos/templates/landing-index.html.j2 | 18 | ||||
-rw-r--r-- | talermerchantdemos/templates/survey-base.html.j2 | 18 | ||||
-rw-r--r-- | talermerchantdemos/templates/survey-error-graceful.html.j2 | 7 | ||||
-rw-r--r-- | talermerchantdemos/templates/survey-error.html.j2 | 24 | ||||
-rw-r--r-- | talermerchantdemos/templates/survey-index.html.j2 | 28 |
17 files changed, 22 insertions, 359 deletions
@@ -6,3 +6,4 @@ config.mk dist/ .vscode *.mo +/local/ @@ -15,7 +15,7 @@ setup-arch: echo "Upgrading System & Installing Python..." sudo pacman -Syu --noconfirm python python-pip python-flask-babel python-poetry python-babel echo "Configuring..." - ./configure --destination=local + ./configure --prefix=local echo "Installing Pip Dependencies..." echo "-> Installing wheel..." pip install wheel @@ -36,7 +36,7 @@ setup-deb: echo "Installing python, python-flask-babel, python-pip, python-is-python3..." sudo apt install -y python3 python3-flask-babel python3-pip python-is-python3 echo "Configuring..." - ./configure --destination=local + ./configure --prefix=local echo "Installing Pip Dependencies..." echo "-> Installing wheel..." pip install wheel @@ -40,7 +40,7 @@ _Note: These instructions assume you are on a debian-based distribution. Other d > ``` 4. Configure things using: > ```bash - > $ ./configure --destination=local + > $ ./configure --prefix=local > ``` 5. Install UWSGI > ```bash @@ -145,7 +145,3 @@ This makes the blog speak UWSGI over unix domain socket: > uwsgi_unixpath = "/tmp/blog.uwsgi" > uwsgi_unixpath_mode = XZY > ``` - -## Notice: Bank - -The bank lives in [merchant-backoffice.git](https://git.taler.net/merchant-backoffice.git) under [/packages/bank](https://git.taler.net/merchant-backoffice.git/tree/packages/bank)
\ No newline at end of file diff --git a/debian/rules b/debian/rules index 482b6b3..8ce5174 100755 --- a/debian/rules +++ b/debian/rules @@ -29,7 +29,6 @@ override_dh_installsystemd: # and dh_installsystemd by default only looks for "<package>.service". dh_installsystemd -ptaler-merchant-demos --name=taler-demo-landing --no-start --no-enable dh_installsystemd -ptaler-merchant-demos --name=taler-demo-blog --no-start --no-enable - dh_installsystemd -ptaler-merchant-demos --name=taler-demo-survey --no-start --no-enable dh_installsystemd -ptaler-merchant-demos --name=taler-demo-donations --no-start --no-enable # final invocation to generate daemon reload dh_installsystemd diff --git a/debian/taler-merchant-demos.taler-demo-survey.service b/debian/taler-merchant-demos.taler-demo-survey.service deleted file mode 100644 index 5014e3b..0000000 --- a/debian/taler-merchant-demos.taler-demo-survey.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Taler Demo Survey Mercchant - -[Service] -User=taler-merchant-demos -ExecStart=/usr/bin/taler-merchant-demos -c /etc/taler/taler-merchant-frontends.conf survey -EnvironmentFile=/etc/taler/taler-merchant-frontends.env -Restart=on-failure -RestartSec=1s - -[Install] -WantedBy=multi-user.target diff --git a/pyproject.toml b/pyproject.toml index 254afa6..e8c2cf2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,11 +27,6 @@ include = [ # Donation files "talermerchantdemos/donations/templates/*.j2", "talermerchantdemos/donations/static/*.css", - # Survey files - "talermerchantdemos/survey/templates/*.j2", - "talermerchantdemos/survey/static/favicon.ico", - "talermerchantdemos/survey/static/*.js", - "talermerchantdemos/survey/static/*.css" ] diff --git a/taler.conf b/taler.conf new file mode 100644 index 0000000..6342f54 --- /dev/null +++ b/taler.conf @@ -0,0 +1,14 @@ +[frontends] +backend_apikey = "secret-token:messi" +backend = http://merchant.taler.test:1180/ + +[taler] +currency = LOCAL + +[blog] +http_port = 8080 +serve = http + +[landing] +http_port = 8080 +serve = http diff --git a/talermerchantdemos/cli.py b/talermerchantdemos/cli.py index ead5aae..ee1be83 100644 --- a/talermerchantdemos/cli.py +++ b/talermerchantdemos/cli.py @@ -172,10 +172,10 @@ def handle_serve_from_config(config_obj, which_shop): ) @click.argument("which-shop") def demos(config, http_port, which_shop): - """WHICH_SHOP is one of: blog, donations, survey or landing.""" + """WHICH_SHOP is one of: blog, donations or landing.""" - if which_shop not in ["blog", "donations", "landing", "survey"]: - print("Please use a valid shop name: blog, donations, landing, survey.") + if which_shop not in ["blog", "donations", "landing"]: + print("Please use a valid shop name: blog, donations, landing.") sys.exit(1) config_obj = TalerConfig.from_file(config) if http_port: diff --git a/talermerchantdemos/landing/landing.py b/talermerchantdemos/landing/landing.py index 746da0b..13c8dc4 100644 --- a/talermerchantdemos/landing/landing.py +++ b/talermerchantdemos/landing/landing.py @@ -154,11 +154,6 @@ def start(lang): else: merchant_donations_url = "#" - if x := os.environ.get("TALER_ENV_URL_MERCHANT_SURVEY"): - merchant_survey_url = "/".join([x.strip("/"), lang]) - else: - merchant_survey_url = "#" - return flask.render_template( "landing-index.html.j2", merchant_currency=CURRENCY, @@ -168,7 +163,6 @@ def start(lang): bank_public_accounts_url=bank_public_accounts_url, merchant_blog_url=merchant_blog_url, merchant_donations_url=merchant_donations_url, - merchant_survey_url=merchant_survey_url, ) diff --git a/talermerchantdemos/survey/__init__.py b/talermerchantdemos/survey/__init__.py deleted file mode 100644 index 2b22f3a..0000000 --- a/talermerchantdemos/survey/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from talermerchantdemos.survey.survey import app - -__all__ = ["app"] diff --git a/talermerchantdemos/survey/survey.py b/talermerchantdemos/survey/survey.py deleted file mode 100644 index cc256d1..0000000 --- a/talermerchantdemos/survey/survey.py +++ /dev/null @@ -1,225 +0,0 @@ -## -# This file is part of GNU TALER. -# Copyright (C) 2017, 2020 Taler Systems SA -# -# TALER is free software; you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free Software -# Foundation; either version 2.1, or (at your option) any later version. -# -# TALER is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License along with -# GNU TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -# -# @author Marcello Stanisci -# @brief Minimal Website to reward users who fill the survey. - -import os -import re -import datetime -import base64 -import uwsgi -import logging -import werkzeug -from urllib.parse import urljoin -import flask -from flask import request -from flask_babel import Babel -from flask_babel import refresh -from flask_babel import force_locale -from flask_babel import gettext -from werkzeug.middleware.proxy_fix import ProxyFix -import traceback -from ..util.talerconfig import TalerConfig, ConfigurationError -from ..httpcommon import ( - backend_get, - backend_post, - self_localized, - BackendException, - make_utility_processor, - get_locale, -) -import sys - -if not sys.version_info.major == 3 and sys.version_info.minor >= 6: - print("Python 3.6 or higher is required.") - print( - "You are using Python {}.{}.".format( - sys.version_info.major, sys.version_info.minor - ) - ) - sys.exit(1) - -app = flask.Flask(__name__, template_folder="../templates", static_folder="../static") -app.wsgi_app = ProxyFix(app.wsgi_app, x_host=1, x_prefix=1) -app.debug = True -app.secret_key = base64.b64encode(os.urandom(64)).decode("utf-8") - -logging.basicConfig() -LOGGER = logging.getLogger(__name__) -LOGGER.setLevel(logging.DEBUG) -try: - BACKEND_URL = uwsgi.opt["backend_url"].decode("utf-8") - CURRENCY = uwsgi.opt["currency"].decode("utf-8") - APIKEY = uwsgi.opt["apikey"].decode("utf-8") -except ConfigurationError as ce: - print(ce) - exit(1) - -BABEL_TRANSLATION_DIRECTORIES = "../translations" - -app.config.from_object(__name__) -babel = Babel(app) -babel.localeselector(get_locale) - -INSTANCED_URL = urljoin(BACKEND_URL, f"instances/survey/") -LOGGER.info("bankend URL: {url}, currency: {c}, apikey: {key}".format( - url=BACKEND_URL, c=CURRENCY, key=APIKEY -)) -LOGGER.info("Using translations from:" + ":".join(list(babel.translation_directories))) -translations = [str(translation) for translation in babel.list_translations()] -if not "en" in translations: - translations.append("en") -LOGGER.info( - "Operating with the following translations available: " + " ".join(translations) -) - -app.add_template_global(self_localized) - - -# Add context processor that will make additional variables -# and functions available in the template. -app.context_processor(make_utility_processor("survey", os.environ.get ("TALER_ENV_URL_MERCHANT_SURVEY"))) - - -## -# Exception handler to capture all the unmanaged errors. -# -# @param e the Exception object, currently unused. -# @return flask-native response object carrying the error message -# (and execution stack!). -@app.errorhandler(Exception) -def internal_error(e): - return flask.render_template("survey-error.html.j2", - page_title=gettext("GNU Taler Demo: Error"), - message=str(e) - ) - -## -# Serve the /favicon.ico requests. -# -# @return the favicon.ico file. -@app.route("/favicon.ico") -def favicon(): - LOGGER.info("will look into: " + os.path.join(app.root_path, "static")) - return flask.send_from_directory( - os.path.join(app.root_path, "static"), - "favicon.ico", - mimetype="image/vnd.microsoft.ico", - ) - - -## -# Tell the backend to 'authorize' a reward; this means that -# the backend will allocate a certain amount to be later -# picked up by the wallet. -# -# @return the URL where to redirect the browser, in order -# for the wallet to pick the reward up, or a error page -# otherwise. -@app.route("/<lang>/submit-survey", methods=["POST"]) -def submit_survey(lang): - reward_spec = dict( - amount=CURRENCY + ":1.0", - next_url=os.environ.get("TALER_ENV_URL_INTRO", "https://taler.net/"), - justification="Payment methods survey", - ) - backend_resp = backend_post( - INSTANCED_URL, "private/rewards", reward_spec, auth_token=APIKEY - ) - return flask.redirect(backend_resp["reward_status_url"]) - - -## -# Serve the main index page, redirecting to /<lang>/ -# -# @return response object of the index page. -@app.route("/") -def index(): - default = "en" - target = flask.request.accept_languages.best_match(translations, default) - return flask.redirect(target + "/", code=302) - - -## -# Serve the internationalized main index page. -# -# @return response object of the index page. -@app.route("/<lang>/", methods=["GET"]) -def start(lang): - LOGGER.info("Serving main page. Currency: {}".format(CURRENCY)) - - # get_locale defaults to english, hence the - # condition below happens only when lang is - # wrong or unsupported, respond 404. - if lang != get_locale(): - raise werkzeug.exceptions.NotFound() - - return flask.render_template( - "survey-index.html.j2", - page_title=gettext("GNU Taler Demo: Survey"), - merchant_currency=CURRENCY, - ) - - -@app.errorhandler(404) -@app.errorhandler(werkzeug.exceptions.NotFound) -def handler_404(e): - return flask.render_template( - "survey-error.html.j2", - page_title=gettext("GNU Taler Demo: Error"), - message=gettext("Page not found"), - ) - - -@app.errorhandler(405) -def handler_405(e): - return flask.render_template( - "survey-error.html.j2", - page_title=gettext("GNU Taler Demo: Error"), - message=gettext("HTTP method not allowed for this page"), - ) - - -@app.errorhandler(BackendException) -def handler_backend_exception(e): - - # The reward reserve was never created - if e.backend_json.get("code") == 2753: - t = flask.render_template( - "survey-error-graceful.html.j2", - page_title=gettext("GNU Taler Demo: Error"), - message="Reward money was never invested, we are sorry!" - ) - return flask.make_response(t, 500) - - # The reward reserve was never created - if e.backend_json.get("code") == 2752: - t = flask.render_template( - "survey-error-graceful.html.j2", - page_title=gettext("GNU Taler Demo: Error"), - message="Reward money got all awarded, please return later!" - ) - return flask.make_response(t, 500) - - - t = flask.render_template( - "survey-error.html.j2", - page_title=gettext("GNU Taler Demo: Error"), - message=e.args[0], - json=e.backend_json, - status_code=e.backend_status, - ) - return flask.make_response(t, 500) diff --git a/talermerchantdemos/templates/common-base.html.j2 b/talermerchantdemos/templates/common-base.html.j2 index 7c6fdd0..f37a306 100644 --- a/talermerchantdemos/templates/common-base.html.j2 +++ b/talermerchantdemos/templates/common-base.html.j2 @@ -65,9 +65,6 @@ <a href="{{ env('TALER_ENV_URL_MERCHANT_DONATIONS', '#') + getlang() + '/' }}" {% if getactive() == 'donations' %} class="active" {% endif %} >{{gettext("Donations")}}</a> - <a href="{{ env('TALER_ENV_URL_MERCHANT_SURVEY', '#') + getlang() + '/' }}" - {% if getactive() == 'survey' %} class="active" {% endif %} - >{{gettext("Survey")}}</a> <script> function handleLang(event){ if (event.type === 'click') { diff --git a/talermerchantdemos/templates/landing-index.html.j2 b/talermerchantdemos/templates/landing-index.html.j2 index 5c7b0e2..0cf4788 100644 --- a/talermerchantdemos/templates/landing-index.html.j2 +++ b/talermerchantdemos/templates/landing-index.html.j2 @@ -62,23 +62,7 @@ </p> </article> <article> - <h2>{{ gettext("Step 5: Survey") }}</h2> - <p> - {{ - gettext("Websites can give rewards to visitors for completing tasks.") + "<br>" + - gettext('You can earn some {currency} coins by filling in our <a href="{url}">survey</a>.').format(url=merchant_survey_url,currency=merchant_currency) - }} - </p> - </article> - <!-- article> - <h2>Step 6: Are you a merchant? Taler has a build-in back-office!</h2> - <p> - If you are a merchant, you can check the <a href="{{ backoffice_url }}">back-office</a> - website to see how your Taler transactions got payed back by bank wire transfers. - </p> - </article --> - <article> - <h2>{{ gettext("Step 6: Reach out to us") }}</h2> + <h2>{{ gettext("Step 5: Reach out to us") }}</h2> <p> {{ gettext("We appreciate feedback about Taler and this demonstrator.") + "<br>" + diff --git a/talermerchantdemos/templates/survey-base.html.j2 b/talermerchantdemos/templates/survey-base.html.j2 deleted file mode 100644 index b9c7fc5..0000000 --- a/talermerchantdemos/templates/survey-base.html.j2 +++ /dev/null @@ -1,18 +0,0 @@ -{% extends "common-base.html.j2" %} - -{% block head %} - <link rel="stylesheet" type="text/css" href="{{ static('colors-survey.css') }}" /> -{% endblock head %} - - -{% block header_content %} - -<h1> -<span class="it"><a href="{{ env('TALER_ENV_URL_MERCHANT_SURVEY', '#') }}">{{ gettext("Survey") }}</a></span></h1> -<p>{{ -gettext("This page demonstrates how to reward visitors for completing small tasks.") + "<br>" + -gettext("Rewarding is a way of offering cash rewards that go straight into a user's wallet.") -}} -</p> - -{% endblock %} diff --git a/talermerchantdemos/templates/survey-error-graceful.html.j2 b/talermerchantdemos/templates/survey-error-graceful.html.j2 deleted file mode 100644 index ece2252..0000000 --- a/talermerchantdemos/templates/survey-error-graceful.html.j2 +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "survey-base.html.j2" %} -{% block main %} - <h1>{{ gettext("Unexpected result") }}</h1> - - <p>{{ message }}</p> - -{% endblock main %} diff --git a/talermerchantdemos/templates/survey-error.html.j2 b/talermerchantdemos/templates/survey-error.html.j2 deleted file mode 100644 index b2f84f9..0000000 --- a/talermerchantdemos/templates/survey-error.html.j2 +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "survey-base.html.j2" %} -{% block main %} - <h1>{{ gettext("Error encountered") }}</h1> - - <p>{{ message }}</p> - - {% if status_code %} - <p> - {{ gettext ("The backend returned status code {code}.").format(code=status_code) }} - </p> - {% endif %} - - {% if json %} - <p>{{gettext("Backend response:")}}</p> - <pre>{{ json }}</pre> - {% endif %} - - {% if stack %} - <p>{{gettext("Stack trace:")}}</p> - <pre> - {{ stack }} - </pre> - {% endif %} -{% endblock main %} diff --git a/talermerchantdemos/templates/survey-index.html.j2 b/talermerchantdemos/templates/survey-index.html.j2 deleted file mode 100644 index 1296546..0000000 --- a/talermerchantdemos/templates/survey-index.html.j2 +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "survey-base.html.j2" %} -{% block main %} - <div> - <p> - {{ - gettext("Please participate in our survey about payment systems and receive a reward in return.") - }} - </p> - </div> - <div> - <form action="{{ (script_name or "") + "/" + getlang() + "/submit-survey" }}" method="post" class="pure-form pure-form-stacked"> - <fieldset> - <legend>{{ gettext("Which payment system do you prefer?") }}</legend> - <label for="option-taler"> - <input id="option-taler" type="radio" name="paypref" value="taler" checked="checked" /> - Taler - </label> - <label for="option-visa"> - <input id="option-visa" type="radio" name="paypref" value="visa" /> - Visa - </label> - </fieldset> - <button name="submit" class="pure-button pure-button-primary" > - {{ gettext("Submit Survey")}} - </button> - </form> - </div> -{% endblock %} |