user can set client.referral
This commit is contained in:
parent
1aff59e112
commit
04bcc24ad7
|
@ -27,6 +27,13 @@
|
|||
<span class="icon mr-3"><i class="fe fe-shield"></i></span>OAuth Endpoints
|
||||
</a>
|
||||
|
||||
{% if current_user.referrals|count > 0 %}
|
||||
<a href="{{ url_for('developer.client_detail_referral', client_id=client.id) }}"
|
||||
class="list-group-item list-group-item-action {{ 'active' if client_details_page == 'referral' }}">
|
||||
<span class="icon mr-3"><i class="fe fe-share"></i></span>Referral
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ url_for('developer.client_detail_advanced', client_id=client.id) }}"
|
||||
class="list-group-item list-group-item-action {{ 'active' if client_details_page == 'advanced' }}">
|
||||
<span class="icon mr-3"><i class="fe fe-alert-octagon"></i></span>Danger
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
{% extends 'developer/client_details/base.html' %}
|
||||
|
||||
{% set client_details_page = "referral" %}
|
||||
|
||||
{% block client_details_content %}
|
||||
<h1 class="h2">Referral</h1>
|
||||
<div class="">
|
||||
If you are in the <a href="{{ url_for('dashboard.referral_route') }}">referral</a> program, you can attach a
|
||||
referral to this website.
|
||||
Any SimpleLogin sign up thanks to the SIWSL on your website will be counted towards this referral.
|
||||
</div>
|
||||
<form method="post" class="mt-3">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="client-select">Referral</label>
|
||||
<select class="form-control" name="referral-id" id="client-select">
|
||||
{% for referral in current_user.referrals %}
|
||||
<option value="{{ referral.id }}"
|
||||
{% if client.referral_id == referral.id %} selected {% endif %}>{{ referral.name }}</option>
|
||||
{% endfor %}
|
||||
{% if client.referral_id is none %}
|
||||
<option value="" selected>No referral selected</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-primary" value="Update">
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -12,7 +12,7 @@ from app.db import Session
|
|||
from app.developer.base import developer_bp
|
||||
from app.email_utils import send_email
|
||||
from app.log import LOG
|
||||
from app.models import Client, RedirectUri, File
|
||||
from app.models import Client, RedirectUri, File, Referral
|
||||
from app.utils import random_string
|
||||
|
||||
|
||||
|
@ -189,3 +189,34 @@ def client_detail_advanced(client_id):
|
|||
return render_template(
|
||||
"developer/client_details/advanced.html", form=form, client=client
|
||||
)
|
||||
|
||||
|
||||
@developer_bp.route("/clients/<client_id>/referral", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def client_detail_referral(client_id):
|
||||
client = Client.get(client_id)
|
||||
if not client:
|
||||
flash("no such app", "warning")
|
||||
return redirect(url_for("developer.index"))
|
||||
|
||||
if client.user_id != current_user.id:
|
||||
flash("you cannot see this app", "warning")
|
||||
return redirect(url_for("developer.index"))
|
||||
|
||||
if request.method == "POST":
|
||||
referral_id = request.form.get("referral-id")
|
||||
if not referral_id:
|
||||
flash("A referral must be selected", "error")
|
||||
return redirect(request.url)
|
||||
|
||||
referral = Referral.get(referral_id)
|
||||
|
||||
if not referral or referral.user_id != current_user.id:
|
||||
flash("something went wrong, refresh the page", "error")
|
||||
return redirect(request.url)
|
||||
|
||||
client.referral_id = referral.id
|
||||
Session.commit()
|
||||
flash(f"Referral {referral.name} is now attached to {client.name}", "success")
|
||||
|
||||
return render_template("developer/client_details/referral.html", client=client)
|
||||
|
|
Loading…
Reference in New Issue