user can remove the app link

This commit is contained in:
Son NK 2021-04-01 14:20:13 +02:00
parent efae1710c8
commit 9757b12b95
2 changed files with 34 additions and 6 deletions

View File

@ -11,7 +11,7 @@
<div class="col">
<h1 class="h3"> Apps </h1>
<div class="small-text">
List of websites/apps that you have used <b>Sign in with SimpleLogin</b> on
List of websites/apps that you have used <b>Sign in with SimpleLogin</b>
</div>
</div>
</div>
@ -29,12 +29,15 @@
<th>
Info
<i class="fe fe-help-circle" data-toggle="tooltip"
title="Info sent to this app/website"></i>
title="Info this app/website receives"></i>
</th>
<th class="text-center">
<th>
First used
<i class="fe fe-help-circle" data-toggle="tooltip"
title="The first time you have used the SimpleLogin on this app/website"></i>
title="The first time you have used the 'Sign in with SimpleLogin' button on this app/website"></i>
</th>
<th>
Actions
</th>
<!--<th class="text-center">Last used</th>-->
</tr>
@ -58,10 +61,18 @@
{% endfor %}
</td>
<td class="text-center">
<td>
{{ client_user.created_at | dt }}
</td>
<td>
<form method="post">
<input type="hidden" name="client-user-id" value="{{ client_user.id }}">
<button class="btn btn-warning">
Remove
</button>
</form>
</td>
</tr>
{% endfor %}

View File

@ -2,11 +2,12 @@
List of apps that user has used via the "Sign in with SimpleLogin"
"""
from flask import render_template
from flask import render_template, request, flash, redirect
from flask_login import login_required, current_user
from sqlalchemy.orm import joinedload
from app.dashboard.base import dashboard_bp
from app.extensions import db
from app.models import (
ClientUser,
)
@ -24,6 +25,22 @@ def app_route():
sorted(client_users, key=lambda cu: cu.client.name)
if request.method == "POST":
client_user_id = request.form.get("client-user-id")
client_user = ClientUser.get(client_user_id)
if not client_user or client_user.user_id != current_user.id:
flash(
"Unknown error, sorry for the inconvenience, refresh the page", "error"
)
return redirect(request.url)
client = client_user.client
ClientUser.delete(client_user_id)
db.session.commit()
flash(f"Link with {client.name} has been removed", "success")
return redirect(request.url)
return render_template(
"dashboard/app.html",
client_users=client_users,