+ On this page, you can create a referral code that you can use when referring people to SimpleLogin.
+ For every user who upgrades, you'll get $5 :).
+ The payout can be initiated any time, just send us an email at
+ hi@simplelogin.io when you want to receive the payout.
+
{% if referrals|length == 0 %}
@@ -24,7 +36,6 @@
- Name
@@ -35,14 +46,13 @@
-
{% set nb_user = referral.nb_user() %}
{% set nb_paid_user = referral.nb_paid_user() %}
{% if nb_user > 0 %}
{{ nb_user }}
{% if nb_user == 1 %} person {% else %} people {% endif %}
- has protected their emails thanks to you!
+ has their online privacy protected thanks to you!
Among them, {{ nb_paid_user }}
{% if nb_paid_user == 1 %} person {% else %} people {% endif %}
@@ -71,7 +81,14 @@
You can also use the referral code {{ referral.code }} when sharing any link on SimpleLogin.
- Just append ?slref={{ referral.code }} to any link on SimpleLogin website.
+ Just append
+
+ ?slref={{ referral.code }}
+
+ to any link on SimpleLogin website.
@@ -91,9 +108,24 @@
+
+
+
-
+
+
+
{% endblock %}
diff --git a/app/dashboard/views/referral.py b/app/dashboard/views/referral.py
index 93129309..c4c2eae2 100644
--- a/app/dashboard/views/referral.py
+++ b/app/dashboard/views/referral.py
@@ -1,3 +1,5 @@
+import re
+
from flask import render_template, request, flash, redirect, url_for
from flask_login import login_required, current_user
@@ -7,21 +9,26 @@ from app.log import LOG
from app.models import Referral
from app.utils import random_string
+_REFERRAL_PATTERN = r"[0-9a-z-_]{3,}"
+
@dashboard_bp.route("/referral", methods=["GET", "POST"])
@login_required
def referral_route():
if request.method == "POST":
if request.form.get("form-name") == "create":
- # Generate a new unique ref code
- code = random_string(15)
- for _ in range(100):
- if not Referral.get_by(code=code):
- # found
- break
+ code = request.form.get("code")
+ if re.fullmatch(_REFERRAL_PATTERN, code) is None:
+ flash(
+ "At least 3 characters. Only lowercase letters, "
+ "numbers, dashes (-) and underscores (_) are currently supported.",
+ "error",
+ )
+ return redirect(url_for("dashboard.referral_route"))
- LOG.warning("Referral Code %s already used", code)
- code = random_string(15)
+ if Referral.get_by(code=code):
+ flash("Code already used", "error")
+ return redirect(url_for("dashboard.referral_route"))
name = request.form.get("name")
referral = Referral.create(user_id=current_user.id, code=code, name=name)