User who has lifetime licence or giveaway manual subscriptions can decide to upgrade to a paid plan
This commit is contained in:
parent
260ded14ea
commit
b838157ad5
|
@ -165,9 +165,18 @@
|
|||
Manage Subscription
|
||||
</a>
|
||||
{% elif manual_sub %}
|
||||
You are on the Premium plan. The plan ends {{ manual_sub.end_at | dt }}.
|
||||
You are on the Premium plan. The plan ends {{ manual_sub.end_at | dt }}
|
||||
({{ manual_sub.end_at.format("YYYY-MM-DD") }}).
|
||||
{% if manual_sub.is_giveaway %}
|
||||
<br>
|
||||
To support SimpleLogin it's possible to change to a paid plan. <br>
|
||||
<a href="{{ url_for('dashboard.pricing') }}" class="btn btn-sm btn-outline-primary">Upgrade</a>
|
||||
{% endif %}
|
||||
{% elif current_user.lifetime %}
|
||||
You have the lifetime licence.
|
||||
<br>
|
||||
To support SimpleLogin it's possible to change to a paid plan. <br>
|
||||
<a href="{{ url_for('dashboard.pricing') }}" class="btn btn-sm btn-outline-primary">Upgrade</a>
|
||||
{% elif current_user.in_trial() %}
|
||||
You are in the trial period. The trial ends {{ current_user.trial_end | dt }}.
|
||||
{% else %}
|
||||
|
|
|
@ -13,8 +13,7 @@ from app.dashboard.base import dashboard_bp
|
|||
@dashboard_bp.route("/pricing", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def pricing():
|
||||
# sanity check: make sure this page is only for free or trial user
|
||||
if not current_user.should_upgrade():
|
||||
if not current_user.can_upgrade():
|
||||
flash("You are already a premium user", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
|
|
|
@ -243,6 +243,23 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
|
||||
return True
|
||||
|
||||
def can_upgrade(self):
|
||||
"""User who has lifetime licence or giveaway manual subscriptions can decide to upgrade to a paid plan"""
|
||||
sub: Subscription = self.get_subscription()
|
||||
# user who has canceled can also re-subscribe
|
||||
if sub and not sub.cancelled:
|
||||
return False
|
||||
|
||||
manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id)
|
||||
# user who has giveaway premium can decide to upgrade
|
||||
if manual_sub and manual_sub.end_at > arrow.now() and not manual_sub.is_giveaway:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
def next_bill_date(self) -> str:
|
||||
sub: Subscription = self.get_subscription()
|
||||
if sub:
|
||||
|
|
Loading…
Reference in a new issue