mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 20:51:29 +02:00
get_subscription should only return *active* subscription.
This commit is contained in:
parent
86e5a44b89
commit
026fe4addd
@ -8,10 +8,10 @@ from app.dashboard.base import dashboard_bp
|
|||||||
@login_required
|
@login_required
|
||||||
def billing():
|
def billing():
|
||||||
# sanity check: make sure this page is only for user who has paddle subscription
|
# sanity check: make sure this page is only for user who has paddle subscription
|
||||||
if not current_user.is_premium():
|
|
||||||
flash("This page is for paid customer only", "warning")
|
|
||||||
return redirect(url_for("dashboard.index"))
|
|
||||||
|
|
||||||
sub = current_user.get_subscription()
|
sub = current_user.get_subscription()
|
||||||
|
|
||||||
|
if not sub:
|
||||||
|
flash("You don't have any active subscription", "warning")
|
||||||
|
return redirect(url_for("dashboard.index"))
|
||||||
|
|
||||||
return render_template("dashboard/billing.html", sub=sub)
|
return render_template("dashboard/billing.html", sub=sub)
|
||||||
|
@ -145,11 +145,6 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||||||
"""user is premium if they have a active subscription"""
|
"""user is premium if they have a active subscription"""
|
||||||
sub: Subscription = self.get_subscription()
|
sub: Subscription = self.get_subscription()
|
||||||
if sub:
|
if sub:
|
||||||
if sub.cancelled:
|
|
||||||
# user is premium until the next billing_date + 1
|
|
||||||
return sub.next_bill_date >= arrow.now().shift(days=-1).date()
|
|
||||||
|
|
||||||
# subscription active, ie not cancelled
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -217,8 +212,19 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||||||
return "Free Plan"
|
return "Free Plan"
|
||||||
|
|
||||||
def get_subscription(self):
|
def get_subscription(self):
|
||||||
|
"""return *active* subscription
|
||||||
|
TODO: support user unsubscribe and re-subscribe
|
||||||
|
"""
|
||||||
sub = Subscription.get_by(user_id=self.id)
|
sub = Subscription.get_by(user_id=self.id)
|
||||||
return sub
|
if sub and sub.cancelled:
|
||||||
|
# sub is active until the next billing_date + 1
|
||||||
|
if sub.next_bill_date >= arrow.now().shift(days=-1).date():
|
||||||
|
return sub
|
||||||
|
else: # past subscription, user is considered not having a subscription
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return sub
|
||||||
|
|
||||||
|
|
||||||
def verified_custom_domains(self):
|
def verified_custom_domains(self):
|
||||||
return CustomDomain.query.filter_by(user_id=self.id, verified=True).all()
|
return CustomDomain.query.filter_by(user_id=self.id, verified=True).all()
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||||
{% if current_user.is_premium() %}
|
{% if current_user.get_subscription() %}
|
||||||
<a class="dropdown-item" href="{{ url_for('dashboard.billing') }}">
|
<a class="dropdown-item" href="{{ url_for('dashboard.billing') }}">
|
||||||
<i class="dropdown-icon fe fe-dollar-sign"></i> Billing
|
<i class="dropdown-icon fe fe-dollar-sign"></i> Billing
|
||||||
</a>
|
</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user