User can update/create referral name
This commit is contained in:
parent
3ce3a05c7b
commit
1667356742
|
@ -19,8 +19,23 @@
|
||||||
|
|
||||||
{% for referral in referrals %}
|
{% for referral in referrals %}
|
||||||
<div class="card p-4 shadow-sm {% if referral.id == highlight_id %} highlight-row {% endif %}">
|
<div class="card p-4 shadow-sm {% if referral.id == highlight_id %} highlight-row {% endif %}">
|
||||||
<div class="mb-3">Referral Code: <b>{{ referral.code }}</b>
|
|
||||||
</div>
|
<form method="post">
|
||||||
|
<input type="hidden" name="form-name" value="update">
|
||||||
|
<input type="hidden" name="referral-id" value="{{ referral.id }}">
|
||||||
|
|
||||||
|
<b>Name</b>
|
||||||
|
<div class="d-flex mb-3">
|
||||||
|
<div class="mr-2" style="min-width: 20em">
|
||||||
|
<input name="name" class="form-control" value="{{ referral.name or '' }}">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button class="btn btn-outline-success">Update</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% if referral.nb_user() > 0 %}
|
{% if referral.nb_user() > 0 %}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
@ -33,8 +48,8 @@
|
||||||
<div>
|
<div>
|
||||||
Please use this referral link to invite your friends trying out SimpleLogin: <br>
|
Please use this referral link to invite your friends trying out SimpleLogin: <br>
|
||||||
|
|
||||||
<div class="d-flex mb-5">
|
<div class="d-flex mb-5" style="max-width: 40em">
|
||||||
<div class="flex-grow-1">
|
<div class="flex-grow-1 mr-1">
|
||||||
<input class="form-control" id="referral-{{ referral.id }}" readonly
|
<input class="form-control" id="referral-{{ referral.id }}" readonly
|
||||||
value="{{ referral.link() }}">
|
value="{{ referral.link() }}">
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,6 +64,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
You can also use the referral code <b>{{ referral.code }}</b> when sharing any link on SimpleLogin. <br>
|
||||||
|
Just append <em>?slref={{ referral.code }}</em> to any link on SimpleLogin website.
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
@ -57,9 +77,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<form method="post" class="mt-6">
|
<form method="post" class="mt-6">
|
||||||
<button class="btn btn-lg btn-success mt-2">Create a new referral code</button>
|
<input type="hidden" name="form-name" value="create">
|
||||||
|
<input name="name" class="form-control"
|
||||||
|
placeholder="Referral name, something to help you remember why you create it :)">
|
||||||
|
<button class="btn btn-success mt-2">Create a new referral code</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -4,7 +4,7 @@ from flask_login import login_required, current_user
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import Referral
|
from app.models import Referral, User
|
||||||
from app.utils import random_string
|
from app.utils import random_string
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,20 +12,33 @@ from app.utils import random_string
|
||||||
@login_required
|
@login_required
|
||||||
def referral_route():
|
def referral_route():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
# Generate a new unique ref code
|
if request.form.get("form-name") == "create":
|
||||||
code = random_string(15)
|
# Generate a new unique ref code
|
||||||
for _ in range(100):
|
|
||||||
if not Referral.get_by(code=code):
|
|
||||||
# found
|
|
||||||
break
|
|
||||||
|
|
||||||
LOG.warning("Referral Code %s already used", code)
|
|
||||||
code = random_string(15)
|
code = random_string(15)
|
||||||
|
for _ in range(100):
|
||||||
|
if not Referral.get_by(code=code):
|
||||||
|
# found
|
||||||
|
break
|
||||||
|
|
||||||
referral = Referral.create(user_id=current_user.id, code=code)
|
LOG.warning("Referral Code %s already used", code)
|
||||||
db.session.commit()
|
code = random_string(15)
|
||||||
flash("A new referral code has been created", "success")
|
|
||||||
return redirect(url_for("dashboard.referral_route", highlight_id=referral.id))
|
name = request.form.get("name")
|
||||||
|
referral = Referral.create(user_id=current_user.id, code=code, name=name)
|
||||||
|
db.session.commit()
|
||||||
|
flash("A new referral code has been created", "success")
|
||||||
|
return redirect(
|
||||||
|
url_for("dashboard.referral_route", highlight_id=referral.id)
|
||||||
|
)
|
||||||
|
elif request.form.get("form-name") == "update":
|
||||||
|
referral_id = request.form.get("referral-id")
|
||||||
|
referral = Referral.get(referral_id)
|
||||||
|
if referral and referral.user_id == current_user.id:
|
||||||
|
referral.name = request.form.get("name")
|
||||||
|
db.session.commit()
|
||||||
|
flash("Referral name updated", "success")
|
||||||
|
return redirect(
|
||||||
|
url_for("dashboard.referral_route", highlight_id=referral.id)
|
||||||
|
|
||||||
# Highlight a referral
|
# Highlight a referral
|
||||||
highlight_id = request.args.get("highlight_id")
|
highlight_id = request.args.get("highlight_id")
|
||||||
|
|
Loading…
Reference in a new issue