Add new emails for maintainer's sake
This commit is contained in:
parent
37584afffd
commit
17cb1c621b
|
@ -0,0 +1,4 @@
|
|||
Hi {{your_name}}!
|
||||
|
||||
Unfortunately, {{user.email}} has chosen to cancel their monthly donation of
|
||||
{{amount}}.
|
|
@ -0,0 +1,5 @@
|
|||
Hi {{your_name}}!
|
||||
|
||||
Good news: {{user.email}} just donated {{amount}}{{frequency}}!
|
||||
|
||||
{{comment}}
|
|
@ -6,6 +6,7 @@ from fosspay.database import db
|
|||
from fosspay.common import *
|
||||
from fosspay.config import _cfg, load_config
|
||||
from fosspay.email import send_thank_you, send_password_reset
|
||||
from fosspay.email import send_new_donation, send_cancellation_notice
|
||||
from fosspay.currency import currency
|
||||
|
||||
import os
|
||||
|
@ -216,6 +217,11 @@ def donate():
|
|||
db.commit()
|
||||
|
||||
send_thank_you(user, amount, type == DonationType.monthly)
|
||||
try:
|
||||
send_new_donation(user, donation)
|
||||
except:
|
||||
# I dunno if this works and I don't have time to test it right now
|
||||
print("send_new_donation is broken")
|
||||
|
||||
if new_account:
|
||||
return { "success": True, "new_account": new_account, "password_reset": user.password_reset }
|
||||
|
@ -291,4 +297,9 @@ def cancel(id):
|
|||
abort(400)
|
||||
donation.active = False
|
||||
db.commit()
|
||||
try:
|
||||
send_cancellation_notice(user, donation)
|
||||
except:
|
||||
# I dunno if this works and I don't have time to test it right now
|
||||
print("send_cancellation_notice is broken")
|
||||
return redirect("/panel")
|
||||
|
|
|
@ -8,7 +8,7 @@ from werkzeug.utils import secure_filename
|
|||
from flask import url_for
|
||||
|
||||
from fosspay.database import db
|
||||
from fosspay.objects import User
|
||||
from fosspay.objects import User, DonationType
|
||||
from fosspay.config import _cfg, _cfgi
|
||||
from fosspay.currency import currency
|
||||
|
||||
|
@ -79,3 +79,52 @@ def send_declined(user, amount):
|
|||
message['Date'] = format_datetime(localtime())
|
||||
smtp.sendmail(_cfg("smtp-from"), [ user.email ], message.as_string())
|
||||
smtp.quit()
|
||||
|
||||
def send_new_donation(user, donation):
|
||||
if _cfg("smtp-host") == "":
|
||||
return
|
||||
smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
|
||||
smtp.ehlo()
|
||||
smtp.starttls()
|
||||
smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
|
||||
with open("emails/new_donation") 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": currency.amount("{:.2f}".format(
|
||||
donation.amount / 100)),
|
||||
"frequency": (" per month"
|
||||
if donation.type == DonationType.monthly else ""),
|
||||
"comment": donation.comment or "",
|
||||
})))
|
||||
message['Subject'] = "New donation on fosspay!"
|
||||
message['From'] = _cfg("smtp-from")
|
||||
message['To'] = f"{_cfg('your-name')} <_cfg('your-email')>"
|
||||
message['Date'] = format_datetime(localtime())
|
||||
smtp.sendmail(_cfg("smtp-from"), [ _cfg('your-email') ], message.as_string())
|
||||
smtp.quit()
|
||||
|
||||
def send_cancellation_notice(user, donation):
|
||||
if _cfg("smtp-host") == "":
|
||||
return
|
||||
smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
|
||||
smtp.ehlo()
|
||||
smtp.starttls()
|
||||
smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
|
||||
with open("emails/cancelled") 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": currency.amount("{:.2f}".format(
|
||||
donation.amount / 100)),
|
||||
})))
|
||||
message['Subject'] = "A monthly donation on fosspay has been cancelled"
|
||||
message['From'] = _cfg("smtp-from")
|
||||
message['To'] = f"{_cfg('your-name')} <_cfg('your-email')>"
|
||||
message['Date'] = format_datetime(localtime())
|
||||
smtp.sendmail(_cfg("smtp-from"), [ _cfg('your-email') ], message.as_string())
|
||||
smtp.quit()
|
||||
|
|
Loading…
Reference in New Issue