diff --git a/config.ini b/config.ini index e262d44..3905c70 100644 --- a/config.ini +++ b/config.ini @@ -3,7 +3,11 @@ port = 5000 bind = 0.0.0.0 base_url = https://ab.21x9.org timezone = Europe/Berlin -mail = abgame@21x9.org +mailform = false +mailserver = localhost:25 +mailto = abgame@21x9.org +mailfrom = abgame@21x9.org +mailsubject = A/B Game Questions separator_char = ; theme = dark animations = 1 @@ -20,3 +24,7 @@ questions_prefix = Es gibt derzeit questions_suffix = Fragen. send_questions = Einreichen! desc = Ein simples Entweder/Oder-Entscheidungsspiel +submit = Absenden +submit_questions =
Bitte gib deine Fragenvorschläge in das untenstehende Feld ein.
Wenn du mir einen Gefallen tun möchtest, gib die Vorschläge im Format "A;B" an und schreibe immer nur ein Fragenpaar in eine Zeile.
Danke!
+submit_thanks_title = Danke! +submit_thanks =Vielen Dank für die Einsendung.
diff --git a/game.py b/game.py index efde033..9993b8b 100755 --- a/game.py +++ b/game.py @@ -1,8 +1,10 @@ #! /bin/python3 -from flask import Flask, render_template +from flask import Flask, render_template, request from configparser import ConfigParser from datetime import datetime +from email.message import EmailMessage +import smtplib import random import pytz @@ -25,16 +27,27 @@ i18n = { 'separator': config.get('i18n', 'separator'), 'mailtext': config.get('i18n', 'mail_link'), 'helptext': config.get('i18n', 'help_link'), - 'help': config.get('i18n', 'help') + 'help': config.get('i18n', 'help'), + 'submit': config.get('i18n', 'submit'), + 'submit_questions': config.get('i18n', 'submit_questions'), + 'submit_thanks_title': config.get('i18n', 'submit_thanks_title'), + 'submit_thanks': config.get('i18n', 'submit_thanks') } conf = { 'separator_char': config.get('main', 'separator_char'), - 'mailto': config.get('main', 'mail'), + 'mailform': config.get('main', 'mailform').lower(), + 'mailserver': config.get('main', 'mailserver'), + 'mailto': config.get('main', 'mailto'), + 'mailfrom': config.get('main', 'mailfrom'), + 'mailsubject': config.get('main', 'mailsubject'), 'url': config.get('main', 'base_url'), 'theme': config.get('main', 'theme'), 'animations': config.get('main', 'animations') } +with open("ab.txt", "r") as f: + num_lines = sum(1 for _ in f) + def getEpoch(): now = datetime.now(tz=tz) epoch = now.timestamp() @@ -52,6 +65,33 @@ def internal_server_error(e): epoch = getEpoch() return render_template('500.html', config=conf, i18n=i18n, epoch=epoch), 500 +if conf['mailform'] == "true": + @app.route("/form") + def mailform(): + epoch = getEpoch() + return render_template('mailform.html', config=conf, i18n=i18n, epoch=epoch, num_lines=num_lines) + + @app.route("/send", methods=['POST', 'GET']) + def sendmail(): + epoch = getEpoch() + + if request.method == 'POST': + mailcontent = request.form['questions'] + else: + mailcontent = request.args.get('questions') + + message = EmailMessage() + message.set_content(mailcontent) + message['Subject'] = conf['mailsubject'] + message['From'] = conf['mailfrom'] + message['To'] = conf['mailto'] + + smtp_server = smtplib.SMTP(conf['mailserver']) + smtp_server.send_message(message) + smtp_server.quit() + + return render_template('thanks.html', config=conf, i18n=i18n, epoch=epoch, questions=mailcontent) + @app.route("/") def hello(): ablines = [] @@ -69,9 +109,6 @@ def hello(): {'A': str(ab[0]), 'B': str(ab[1])} ) - with open("ab.txt", "r") as f: - num_lines = sum(1 for _ in f) - return render_template('index.html', content=ablines, config=conf, i18n=i18n, num_lines=num_lines, epoch=epoch) def getContent(): diff --git a/static/css/base.css b/static/css/base.css index 918ed30..dfb44cc 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -48,6 +48,14 @@ a:hover #help { transform: translate(-50%); } +textarea { + height: 250px; + width: 100%; + background-color: var(--bg-b); + color: var(--fg-b); + border: 1px solid var(--bg-a); +} + #background { overflow: hidden; position: absolute; @@ -98,6 +106,10 @@ a:hover #help { transform: translate(-50%, -50%); } +.form { + padding: 20px; +} + .ab { float: none; border-radius: 10px; diff --git a/templates/base.html b/templates/base.html index 09c5da4..e664790 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,9 +7,6 @@