diff --git a/web/app.py b/web/app.py index 95f1387..ce34518 100644 --- a/web/app.py +++ b/web/app.py @@ -19,6 +19,9 @@ def create_app() -> flask.Flask: app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1 ) + import tos + tos.register(app) + @app.context_processor def inject_variables(): return { @@ -59,41 +62,6 @@ def create_app() -> flask.Flask: return flask.render_template(f'legal/{subpath}.html', verify=emoji) - @app.route('/api/tos-verification', methods=['POST']) - def tos_verification_api(): - if not flask.request.headers.get('Authorization') == os.getenv('TOS_VERIFICATION_KEY'): - return 'Unauthorized', 401 - - code = secrets.token_urlsafe(6) - emoji = random.choice(open('config/emojis.txt', encoding='utf8').read()) - - if not os.path.exists('data/tos.json'): - open('data/tos.json', 'w', encoding='utf8').write('{}') - - try: - data = json.load(open('data/tos.json', encoding='utf8')) - except json.decoder.JSONDecodeError: - data = {} - - data[code] = emoji - json.dump(data, open('data/tos.json', 'w', encoding='utf8')) - - return { - 'code': code, - 'emoji': emoji - } - - @app.route('/api/tos-verification/', methods=['DELETE']) - def tos_verification_api_delete(code): - if not flask.request.headers.get('Authorization') == os.getenv('TOS_VERIFICATION_KEY'): - return 'Unauthorized', 401 - - data = json.load(open('data/tos.json', encoding='utf8')) - del data[code] - json.dump(data, open('data/tos.json', 'w', encoding='utf8')) - - return 'Removed.', 204 - return app production = create_app() diff --git a/web/templates/legal/imprint.html b/web/templates/legal/imprint.html index 9a5b1d8..bc1fc90 100644 --- a/web/templates/legal/imprint.html +++ b/web/templates/legal/imprint.html @@ -1,18 +1 @@ -{% include 'parts/begin.html' %} - -
-

Impressum (Imprint)

-

- My name is Walter Hartwell White. I live at 308 Negra Arroyo Lane, Albuquerque, New Mexico, 87104. -

- -

- Hierbei handelt es sich gemäß § 5 TMG um eine private Internetseite für Freunde und Bekannte ohne kommerzielle Interessen. - Entsprechend entfällt die - Notwendigkeit - - eines Impressums. -

-
- -{% include 'parts/end.html' %} + \ No newline at end of file diff --git a/web/tos.py b/web/tos.py new file mode 100644 index 0000000..822e372 --- /dev/null +++ b/web/tos.py @@ -0,0 +1,45 @@ +import os +import json +import flask +import random +import secrets + +from dotenv import load_dotenv + +load_dotenv() + +def register(app): + @app.route('/api/tos-verification', methods=['POST']) + def tos_verification_api(): + if not flask.request.headers.get('Authorization') == os.getenv('TOS_VERIFICATION_KEY'): + return 'Unauthorized', 401 + + code = secrets.token_urlsafe(6) + emoji = random.choice(open('config/emojis.txt', encoding='utf8').read()) + + if not os.path.exists('data/tos.json'): + open('data/tos.json', 'w', encoding='utf8').write('{}') + + try: + data = json.load(open('data/tos.json', encoding='utf8')) + except json.decoder.JSONDecodeError: + data = {} + + data[code] = emoji + json.dump(data, open('data/tos.json', 'w', encoding='utf8')) + + return { + 'code': code, + 'emoji': emoji + } + + @app.route('/api/tos-verification/', methods=['DELETE']) + def tos_verification_api_delete(code): + if not flask.request.headers.get('Authorization') == os.getenv('TOS_VERIFICATION_KEY'): + return 'Unauthorized', 401 + + data = json.load(open('data/tos.json', encoding='utf8')) + del data[code] + json.dump(data, open('data/tos.json', 'w', encoding='utf8')) + + return 'Removed.', 204