User can update/create referral name
This commit is contained in:
parent
3ce3a05c7b
commit
1667356742
|
@ -19,8 +19,23 @@
|
|||
|
||||
{% for referral in referrals %}
|
||||
<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>
|
||||
|
||||
<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 %}
|
||||
<div class="mb-3">
|
||||
|
@ -33,8 +48,8 @@
|
|||
<div>
|
||||
Please use this referral link to invite your friends trying out SimpleLogin: <br>
|
||||
|
||||
<div class="d-flex mb-5">
|
||||
<div class="flex-grow-1">
|
||||
<div class="d-flex mb-5" style="max-width: 40em">
|
||||
<div class="flex-grow-1 mr-1">
|
||||
<input class="form-control" id="referral-{{ referral.id }}" readonly
|
||||
value="{{ referral.link() }}">
|
||||
</div>
|
||||
|
@ -49,6 +64,11 @@
|
|||
</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>
|
||||
{% endfor %}
|
||||
|
||||
|
@ -57,9 +77,10 @@
|
|||
{% endif %}
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -4,7 +4,7 @@ from flask_login import login_required, current_user
|
|||
from app.dashboard.base import dashboard_bp
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import Referral
|
||||
from app.models import Referral, User
|
||||
from app.utils import random_string
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ from app.utils import random_string
|
|||
@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):
|
||||
|
@ -22,10 +23,22 @@ def referral_route():
|
|||
LOG.warning("Referral Code %s already used", code)
|
||||
code = random_string(15)
|
||||
|
||||
referral = Referral.create(user_id=current_user.id, code=code)
|
||||
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))
|
||||
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_id = request.args.get("highlight_id")
|
||||
|
|
Loading…
Reference in a new issue