lil' cleanup

This commit is contained in:
nsde 2023-08-27 18:10:10 +02:00
parent e2d29c844a
commit c9ca4d8873
3 changed files with 49 additions and 53 deletions

View file

@ -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/<code>', 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()

View file

@ -1,18 +1 @@
{% include 'parts/begin.html' %}
<main>
<h1>Impressum (Imprint)</h1>
<p>
<s>My name is Walter Hartwell White. I live at 308 Negra Arroyo Lane, Albuquerque, New Mexico, 87104.</s>
</p>
<p>
Hierbei handelt es sich gemäß § 5 TMG um eine private Internetseite für Freunde und Bekannte ohne kommerzielle Interessen.
Entsprechend entfällt die <a target="_blank" href="https://www.bmuv.de/themen/verbraucherschutz-im-bmuv/digitaler-verbraucherschutz/impressumspflicht#c66866">
Notwendigkeit
</a>
eines Impressums.
</p>
</main>
{% include 'parts/end.html' %}
<meta http-equiv="REFRESH" content="0; url=https://youtu.be/dQw4w9WgXcQ">

45
web/tos.py Normal file
View file

@ -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/<code>', 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