Split lifetime licence to a separate page
This commit is contained in:
parent
abb2584a38
commit
5053d343d1
|
@ -12,4 +12,5 @@ from .views import (
|
|||
mfa_setup,
|
||||
mfa_cancel,
|
||||
domain_detail,
|
||||
lifetime_licence,
|
||||
)
|
||||
|
|
29
app/dashboard/templates/dashboard/lifetime_licence.html
Normal file
29
app/dashboard/templates/dashboard/lifetime_licence.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
{% extends 'default.html' %}
|
||||
|
||||
{% set active_page = "dashboard" %}
|
||||
|
||||
{% block title %}
|
||||
Lifetime Licence
|
||||
{% endblock %}
|
||||
|
||||
{% block default_content %}
|
||||
<div class="bg-white p-6" style="max-width: 60em; margin: auto">
|
||||
<h1 class="h2">Lifetime Licence</h1>
|
||||
|
||||
<div class="mb-4">
|
||||
If you have a lifetime licence, please paste it here. <br>
|
||||
For information, we offer free premium account for education (student, professor or technical staff working at
|
||||
an educational institute). <br>
|
||||
Drop us an email at <a href="mailto:hi@simplelogin.io">hi@simplelogin.io</a> with your student ID or certificate to get the lifetime licence.
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
{{ coupon_form.csrf_token }}
|
||||
|
||||
{{ coupon_form.code(class="form-control", placeholder="Licence Code") }}
|
||||
{{ render_field_errors(coupon_form.code) }}
|
||||
<button class="btn btn-success mt-2">Apply</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -46,7 +46,8 @@
|
|||
|
||||
<div class="mb-3">
|
||||
Please note that Paddle only supports bank card or PayPal. <br>
|
||||
Send us an email at <a href="mailto:hi@simplelogin.io">hi@simplelogin.io</a> if you need other payment options (e.g. IBAN transfer).
|
||||
Send us an email at <a href="mailto:hi@simplelogin.io">hi@simplelogin.io</a> if you need other payment options
|
||||
(e.g. IBAN transfer).
|
||||
</div>
|
||||
|
||||
<button class="btn btn-success" onclick="upgrade({{ PADDLE_MONTHLY_PRODUCT_ID }})">
|
||||
|
@ -60,24 +61,8 @@
|
|||
</button>
|
||||
|
||||
<hr class="my-6">
|
||||
|
||||
<form method="post">
|
||||
{{ coupon_form.csrf_token }}
|
||||
<input type="hidden" name="form-name" value="create">
|
||||
|
||||
<div class="font-weight-bold mb-2">Coupon</div>
|
||||
<div class="small-text">
|
||||
If you have a lifetime coupon, please paste it here. <br>
|
||||
For information, we offer free premium account for education (student, professor or technical staff working at
|
||||
an educational institute). <br>
|
||||
Drop us an email at <a href="mailto:hi@simplelogin.io">hi@simplelogin.io</a> with your student ID or certificate to get the coupon.
|
||||
</div>
|
||||
|
||||
|
||||
{{ coupon_form.code(class="form-control", placeholder="Coupon") }}
|
||||
{{ render_field_errors(coupon_form.code) }}
|
||||
<button class="btn btn-success mt-2">Apply</button>
|
||||
</form>
|
||||
If you have a lifetime licence, please go to this page to apply your licence code.
|
||||
<a href="{{ url_for('dashboard.lifetime_licence') }}">Lifetime Licence</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
57
app/dashboard/views/lifetime_licence.py
Normal file
57
app/dashboard/views/lifetime_licence.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
from flask import render_template, flash, redirect, url_for
|
||||
from flask_login import login_required, current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, validators
|
||||
|
||||
from app.config import (
|
||||
PADDLE_VENDOR_ID,
|
||||
PADDLE_MONTHLY_PRODUCT_ID,
|
||||
PADDLE_YEARLY_PRODUCT_ID,
|
||||
URL,
|
||||
ADMIN_EMAIL,
|
||||
)
|
||||
from app.dashboard.base import dashboard_bp
|
||||
from app.email_utils import send_email
|
||||
from app.extensions import db
|
||||
from app.models import LifetimeCoupon
|
||||
|
||||
|
||||
class CouponForm(FlaskForm):
|
||||
code = StringField("Coupon Code", validators=[validators.DataRequired()])
|
||||
|
||||
|
||||
@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.is_premium():
|
||||
flash("You are already a premium user", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
coupon_form = CouponForm()
|
||||
|
||||
if coupon_form.validate_on_submit():
|
||||
code = coupon_form.code.data
|
||||
|
||||
coupon = LifetimeCoupon.get_by(code=code)
|
||||
|
||||
if coupon and coupon.nb_used > 0:
|
||||
coupon.nb_used -= 1
|
||||
current_user.lifetime = True
|
||||
db.session.commit()
|
||||
|
||||
# notify admin
|
||||
send_email(
|
||||
ADMIN_EMAIL,
|
||||
subject=f"User {current_user.id} used lifetime coupon. Coupon nb_used: {coupon.nb_used}",
|
||||
plaintext="",
|
||||
html="",
|
||||
)
|
||||
|
||||
flash("You are upgraded to lifetime premium!", "success")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
else:
|
||||
flash(f"Code *{code}* expired or invalid", "warning")
|
||||
|
||||
return render_template("dashboard/lifetime_licence.html", coupon_form=coupon_form)
|
|
@ -1,23 +1,13 @@
|
|||
from flask import render_template, flash, redirect, url_for
|
||||
from flask_login import login_required, current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, validators
|
||||
|
||||
from app.config import (
|
||||
PADDLE_VENDOR_ID,
|
||||
PADDLE_MONTHLY_PRODUCT_ID,
|
||||
PADDLE_YEARLY_PRODUCT_ID,
|
||||
URL,
|
||||
ADMIN_EMAIL,
|
||||
)
|
||||
from app.dashboard.base import dashboard_bp
|
||||
from app.email_utils import send_email
|
||||
from app.extensions import db
|
||||
from app.models import LifetimeCoupon
|
||||
|
||||
|
||||
class CouponForm(FlaskForm):
|
||||
code = StringField("Coupon Code", validators=[validators.DataRequired()])
|
||||
|
||||
|
||||
@dashboard_bp.route("/pricing", methods=["GET", "POST"])
|
||||
|
@ -28,39 +18,12 @@ def pricing():
|
|||
flash("You are already a premium user", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
coupon_form = CouponForm()
|
||||
|
||||
if coupon_form.validate_on_submit():
|
||||
code = coupon_form.code.data
|
||||
|
||||
coupon = LifetimeCoupon.get_by(code=code)
|
||||
|
||||
if coupon and coupon.nb_used > 0:
|
||||
coupon.nb_used -= 1
|
||||
current_user.lifetime = True
|
||||
db.session.commit()
|
||||
|
||||
# notify admin
|
||||
send_email(
|
||||
ADMIN_EMAIL,
|
||||
subject=f"User {current_user.id} used lifetime coupon. Coupon nb_used: {coupon.nb_used}",
|
||||
plaintext="",
|
||||
html="",
|
||||
)
|
||||
|
||||
flash("You are upgraded to lifetime premium!", "success")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
else:
|
||||
flash(f"Coupon *{code}* expired or invalid", "warning")
|
||||
|
||||
return render_template(
|
||||
"dashboard/pricing.html",
|
||||
PADDLE_VENDOR_ID=PADDLE_VENDOR_ID,
|
||||
PADDLE_MONTHLY_PRODUCT_ID=PADDLE_MONTHLY_PRODUCT_ID,
|
||||
PADDLE_YEARLY_PRODUCT_ID=PADDLE_YEARLY_PRODUCT_ID,
|
||||
success_url=URL + "/dashboard/subscription_success",
|
||||
coupon_form=coupon_form,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue