allow user having manual sub or canceled sub to upgrade to lifetime

This commit is contained in:
Son NK 2020-04-11 10:47:32 +02:00
parent 89c41f972c
commit a0cdf3ae95
2 changed files with 10 additions and 4 deletions

View File

@ -23,9 +23,15 @@ class CouponForm(FlaskForm):
@dashboard_bp.route("/lifetime_licence", methods=["GET", "POST"])
@login_required
def lifetime_licence():
# sanity check: make sure this page is only for free user
if current_user.lifetime_or_active_subscription():
flash("You are already a premium user", "warning")
if current_user.lifetime:
flash("You already have a lifetime licence", "warning")
return redirect(url_for("dashboard.index"))
# user needs to cancel active subscription first
# to avoid being charged
sub = current_user.get_subscription()
if sub and not sub.cancelled:
flash("Please cancel your current subscription first", "warning")
return redirect(url_for("dashboard.index"))
coupon_form = CouponForm()

View File

@ -322,7 +322,7 @@ class User(db.Model, ModelMixin, UserMixin):
names = self.name.split(" ")
return "".join([n[0].upper() for n in names if n])
def get_subscription(self):
def get_subscription(self) -> "Subscription":
"""return *active* subscription
TODO: support user unsubscribe and re-subscribe
"""