diff --git a/emails/thank-you b/emails/thank-you new file mode 100644 index 0000000..6d45485 --- /dev/null +++ b/emails/thank-you @@ -0,0 +1,19 @@ +Thank you for donating! + +Receipt: + +{{#monthly}} +Monthly donation ${{amount}} +{{/monthly}} +{{^monthly}} +One-time donation ${{amount}} +{{/monthly}} + +You can view and manage your donations online here: + +{{root}}/panel + +Thanks again! If you have questions, contact {{your_email}}. + +-- +{{your_name}} diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index ab42cb6..572c3cb 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -5,6 +5,7 @@ from fosspay.objects import * from fosspay.database import db from fosspay.common import * from fosspay.config import _cfg, load_config +from fosspay.email import send_thank_you import os import locale @@ -125,6 +126,8 @@ def donate(): type = DonationType.one_time else: type = DonationType.monthly + + amount = int(amount) except: return { "success": False, "reason": "Invalid request" }, 400 @@ -161,6 +164,8 @@ def donate(): db.commit() + send_thank_you(user, amount, type == DonationType.monthly) + if new_account: return { "success": True, "new_account": new_account, "password_reset": user.password_reset } else: diff --git a/fosspay/email.py b/fosspay/email.py new file mode 100644 index 0000000..0d8ab73 --- /dev/null +++ b/fosspay/email.py @@ -0,0 +1,33 @@ +import smtplib +import pystache +import os +import html.parser +from email.mime.text import MIMEText +from werkzeug.utils import secure_filename +from flask import url_for + +from fosspay.database import db +from fosspay.objects import User +from fosspay.config import _cfg, _cfgi + +def send_thank_you(user, amount, monthly): + if _cfg("smtp-host") == "": + return + smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port")) + smtp.login(_cfg("smtp-user"), _cfg("smtp-password")) + with open("emails/thank-you") as f: + message = MIMEText(html.parser.HTMLParser().unescape(\ + pystache.render(f.read(), { + "user": user, + "root": _cfg("protocol") + "://" + _cfg("domain"), + "your_name": _cfg("your-name"), + "amount": "{:.2f}".format(amount / 100), + "monthly": monthly, + "your_email": _cfg("your-email") + }))) + message['X-MC-PreserveRecipients'] = "false" + message['Subject'] = "Thank you for your donation!" + message['From'] = _cfg("smtp-from") + message['To'] = user.email + smtp.sendmail(_cfg("smtp-from"), [ user.email ], message.as_string()) + smtp.quit() diff --git a/templates/index.html b/templates/index.html index 404c40b..0f90ea4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -78,7 +78,7 @@ window.email = "{{user.email}}";
$ -
diff --git a/templates/login.html b/templates/login.html index a0b3760..1f603e5 100644 --- a/templates/login.html +++ b/templates/login.html @@ -18,12 +18,13 @@ {% endif %}
- +
+ Reset password