From 5053d343d1747f82ad84df51680656ddca6d07d1 Mon Sep 17 00:00:00 2001 From: Son NK Date: Fri, 3 Jan 2020 22:40:44 +0100 Subject: [PATCH] Split lifetime licence to a separate page --- app/dashboard/__init__.py | 1 + .../templates/dashboard/lifetime_licence.html | 29 ++++++++++ .../templates/dashboard/pricing.html | 23 ++------ app/dashboard/views/lifetime_licence.py | 57 +++++++++++++++++++ app/dashboard/views/pricing.py | 37 ------------ 5 files changed, 91 insertions(+), 56 deletions(-) create mode 100644 app/dashboard/templates/dashboard/lifetime_licence.html create mode 100644 app/dashboard/views/lifetime_licence.py diff --git a/app/dashboard/__init__.py b/app/dashboard/__init__.py index 3c3f87f8..4fa49b9a 100644 --- a/app/dashboard/__init__.py +++ b/app/dashboard/__init__.py @@ -12,4 +12,5 @@ from .views import ( mfa_setup, mfa_cancel, domain_detail, + lifetime_licence, ) diff --git a/app/dashboard/templates/dashboard/lifetime_licence.html b/app/dashboard/templates/dashboard/lifetime_licence.html new file mode 100644 index 00000000..1e1bf09a --- /dev/null +++ b/app/dashboard/templates/dashboard/lifetime_licence.html @@ -0,0 +1,29 @@ +{% extends 'default.html' %} + +{% set active_page = "dashboard" %} + +{% block title %} + Lifetime Licence +{% endblock %} + +{% block default_content %} +
+

Lifetime Licence

+ +
+ If you have a lifetime licence, please paste it here.
+ For information, we offer free premium account for education (student, professor or technical staff working at + an educational institute).
+ Drop us an email at hi@simplelogin.io with your student ID or certificate to get the lifetime licence. +
+ +
+ {{ coupon_form.csrf_token }} + + {{ coupon_form.code(class="form-control", placeholder="Licence Code") }} + {{ render_field_errors(coupon_form.code) }} + +
+
+ +{% endblock %} \ No newline at end of file diff --git a/app/dashboard/templates/dashboard/pricing.html b/app/dashboard/templates/dashboard/pricing.html index b3f43b70..923b4815 100644 --- a/app/dashboard/templates/dashboard/pricing.html +++ b/app/dashboard/templates/dashboard/pricing.html @@ -46,7 +46,8 @@
Please note that Paddle only supports bank card or PayPal.
- Send us an email at hi@simplelogin.io if you need other payment options (e.g. IBAN transfer). + Send us an email at hi@simplelogin.io if you need other payment options + (e.g. IBAN transfer).

- -
- {{ coupon_form.csrf_token }} - - -
Coupon
-
- If you have a lifetime coupon, please paste it here.
- For information, we offer free premium account for education (student, professor or technical staff working at - an educational institute).
- Drop us an email at hi@simplelogin.io with your student ID or certificate to get the coupon. -
- - - {{ coupon_form.code(class="form-control", placeholder="Coupon") }} - {{ render_field_errors(coupon_form.code) }} - -
+ If you have a lifetime licence, please go to this page to apply your licence code. + Lifetime Licence diff --git a/app/dashboard/views/lifetime_licence.py b/app/dashboard/views/lifetime_licence.py new file mode 100644 index 00000000..66511abb --- /dev/null +++ b/app/dashboard/views/lifetime_licence.py @@ -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) diff --git a/app/dashboard/views/pricing.py b/app/dashboard/views/pricing.py index aa74ea34..d29891bc 100644 --- a/app/dashboard/views/pricing.py +++ b/app/dashboard/views/pricing.py @@ -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, )