From c1bd2f83e39635a96ba9ca010d635ca2bdfc2880 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sun, 23 Feb 2020 17:01:23 +0700 Subject: [PATCH] Remind user that their manual sub is ending soon. --- app/models.py | 2 + cron.py | 37 ++++++++++++++++++- crontab.yml | 6 +++ .../manual-subscription-end.html | 26 +++++++++++++ .../transactional/manual-subscription-end.txt | 15 ++++++++ 5 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 templates/emails/transactional/manual-subscription-end.html create mode 100644 templates/emails/transactional/manual-subscription-end.txt diff --git a/app/models.py b/app/models.py index 80d4e5bd..4d71fa11 100644 --- a/app/models.py +++ b/app/models.py @@ -755,6 +755,8 @@ class ManualSubscription(db.Model, ModelMixin): # for storing note about this subscription comment = db.Column(db.Text, nullable=True) + user = db.relationship(User) + class DeletedAlias(db.Model, ModelMixin): """Store all deleted alias to make sure they are NOT reused""" diff --git a/cron.py b/cron.py index c7e0175f..62d850f3 100644 --- a/cron.py +++ b/cron.py @@ -3,7 +3,7 @@ import argparse import arrow from app.config import IGNORED_EMAILS, ADMIN_EMAIL -from app.email_utils import send_email, send_trial_end_soon_email +from app.email_utils import send_email, send_trial_end_soon_email, render from app.extensions import db from app.log import LOG from app.models import ( @@ -14,6 +14,7 @@ from app.models import ( ForwardEmail, CustomDomain, Client, + ManualSubscription, ) from server import create_app @@ -29,6 +30,35 @@ def notify_trial_end(): send_trial_end_soon_email(user) +def notify_manual_sub_end(): + for manual_sub in ManualSubscription.query.all(): + need_reminder = False + if arrow.now().shift(days=14) > manual_sub.end_at > arrow.now().shift(days=13): + need_reminder = True + elif arrow.now().shift(days=4) > manual_sub.end_at > arrow.now().shift(days=3): + need_reminder = True + + if need_reminder: + user = manual_sub.user + LOG.debug("Remind user %s that their manual sub is ending soon", user) + send_email( + user.email, + f"Your trial will end soon {user.name}", + render( + "transactional/manual-subscription-end.txt", + name=user.name, + user=user, + manual_sub=manual_sub, + ), + render( + "transactional/manual-subscription-end.html", + name=user.name, + user=user, + manual_sub=manual_sub, + ), + ) + + def stats(): """send admin stats everyday""" if not ADMIN_EMAIL: @@ -118,7 +148,7 @@ if __name__ == "__main__": "--job", help="Choose a cron job to run", type=str, - choices=["stats", "notify_trial_end",], + choices=["stats", "notify_trial_end", "notify_manual_subscription_end"], ) args = parser.parse_args() @@ -131,3 +161,6 @@ if __name__ == "__main__": elif args.job == "notify_trial_end": LOG.d("Notify users with trial ending soon") notify_trial_end() + elif args.job == "notify_manual_subscription_end": + LOG.d("Notify users with manual subscription ending soon") + notify_manual_sub_end() diff --git a/crontab.yml b/crontab.yml index 373138ae..fae823b4 100644 --- a/crontab.yml +++ b/crontab.yml @@ -10,3 +10,9 @@ jobs: shell: /bin/bash schedule: "0 8 * * *" captureStderr: true + + - name: SimpleLogin Notify Manual Subscription Ends + command: python /code/cron.py -j notify_manual_subscription_end + shell: /bin/bash + schedule: "0 9 * * *" + captureStderr: true diff --git a/templates/emails/transactional/manual-subscription-end.html b/templates/emails/transactional/manual-subscription-end.html new file mode 100644 index 00000000..724f6a90 --- /dev/null +++ b/templates/emails/transactional/manual-subscription-end.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block content %} + {% if name %} + {{ render_text("Hi " + name + ",") }} + {% else %} + {{ render_text("Hi,") }} + {% endif %} + + {{ render_text("Your subscription will end " + manual_sub.end_at.humanize() + ".") }} + + {{ render_text("When the subscription ends:") }} + + {{ render_text("- All aliases/domains/directories you have created are kept and continue working normally.") }} + {{ render_text("- You cannot create new aliases if you exceed the free plan limit, i.e. have more than 5 aliases.") }} + {{ render_text("- As features like catch-all or directory allow you to create aliases on-the-fly, those aliases cannot be automatically created if you have more than 5 aliases.") }} + {{ render_text("- You cannot add new domain or directory.") }} + + {{ render_text('You can upgrade today to continue using all these Premium features (and much more coming).') }} + + {{ render_text('Thanks,
SimpleLogin Team.') }} + {{ render_text('P.S. If you have any questions or need any help, please don\'t hesitate to reach out. You can simply reply to this email or reach us via Twitter/Github.') }} + + +{% endblock %} + diff --git a/templates/emails/transactional/manual-subscription-end.txt b/templates/emails/transactional/manual-subscription-end.txt new file mode 100644 index 00000000..abfc69a6 --- /dev/null +++ b/templates/emails/transactional/manual-subscription-end.txt @@ -0,0 +1,15 @@ +Hi {{name}} + +Your subscription will end {{ manual_sub.end_at.humanize() }}. + +When the subscription ends: + +- All aliases/domains/directories you have created are kept and continue working. +- You cannot create new aliases if you exceed the free plan limit, i.e. have more than 5 aliases. +- As features like "catch-all" or "directory" allow you to create aliases on-the-fly, those aliases cannot be automatically created if you have more than 5 aliases. +- You cannot add new domain or directory. + +You can upgrade today to continue using all these Premium features (and much more coming). + +Best, +Son - SimpleLogin founder.