remove partner code

This commit is contained in:
Son NK 2019-07-23 22:57:30 +02:00 committed by Son NK
parent 01e19485eb
commit ea123b0922
3 changed files with 16 additions and 65 deletions

View File

@ -25,13 +25,9 @@ else:
load_dotenv()
# Constants
PARTNER_CODES = ["SL2019"]
# Allow user to have 1 year of premium: set the expiration_date to 1 year more
PROMO_CODE = "SIMPLEISBETTER"
# Server url
URL = os.environ["URL"]
print(">>> URL:", URL)

View File

@ -33,21 +33,6 @@
{{ render_field_errors(form.website) }}
</div>
<!-- Possibility to bypass using promo code. Only applied for user already authenticated -->
{% if current_user.is_authenticated %}
<hr>
<h4 class="text-center">
Or if you have a <em>partner code</em>, you can become a partner right away!
</h4>
<br>
<div class="form-group">
<label class="form-label">Partner Code</label>
{{ form.partner_code(class="form-control", type="text", placeholder="Partner Code") }}
{{ render_field_errors(form.partner_code) }}
</div>
{% endif %}
<div class="form-footer">
<button type="submit" class="btn btn-primary btn-block">Become a Partner</button>
</div>

View File

@ -3,7 +3,6 @@ from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import StringField
from app.config import PARTNER_CODES
from app.email_utils import notify_admin
from app.extensions import db
from app.models import Partner
@ -15,7 +14,6 @@ class BecomePartnerForm(FlaskForm):
name = StringField("Name")
website = StringField("Website")
additional_information = StringField("Additional Information")
partner_code = StringField("Partner Code")
@partner_bp.route("/become", methods=["GET", "POST"])
@ -23,54 +21,26 @@ def become():
form = BecomePartnerForm(request.form)
if form.validate_on_submit():
# bypass the application
if form.partner_code.data:
if not current_user.is_authenticated:
raise Exception("only authenticated user can enter partner code")
partner = Partner.create(
email=form.email.data,
name=form.name.data,
website=form.website.data,
additional_information=form.additional_information.data,
)
if form.partner_code.data in PARTNER_CODES:
notify_admin(
f"User {current_user.name} has become partner!",
{current_user.email},
)
if current_user.is_authenticated:
partner.user_id = current_user.id
current_user.is_developer = True
db.session.commit()
db.session.commit()
flash(
"Congratulations, you are now a SimpleLogin partner! "
"You will have access to tech resources on SimpleLogin.",
"success",
)
notify_admin(
f"New partner {partner.name} {partner.email} has signed up!",
partner.website,
)
return redirect(url_for("developer.index"))
else:
error = (
"The partner code is unknown. Are you sure this is the right code?"
)
return render_template("partner/become.html", form=form, error=error)
else:
partner = Partner.create(
email=form.email.data,
name=form.name.data,
website=form.website.data,
additional_information=form.additional_information.data,
)
if current_user.is_authenticated:
partner.user_id = current_user.id
db.session.commit()
notify_admin(
f"New partner {partner.name} {partner.email} has signed up!",
partner.website,
)
flash(
"Your request has been submitted, we'll come back to you asap!",
"success",
)
flash(
"Your request has been submitted, we'll come back to you asap!", "success"
)
return redirect(url_for("partner.become"))