From 9757b12b956a95f8a5abe047d049d236b71c749d Mon Sep 17 00:00:00 2001
From: Son NK <>
Date: Thu, 1 Apr 2021 14:20:13 +0200
Subject: [PATCH] user can remove the app link
---
app/dashboard/templates/dashboard/app.html | 21 ++++++++++++++++-----
app/dashboard/views/app.py | 19 ++++++++++++++++++-
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/app/dashboard/templates/dashboard/app.html b/app/dashboard/templates/dashboard/app.html
index 2dafdd1a..f64fba62 100644
--- a/app/dashboard/templates/dashboard/app.html
+++ b/app/dashboard/templates/dashboard/app.html
@@ -11,7 +11,7 @@
Apps
- List of websites/apps that you have used Sign in with SimpleLogin on
+ List of websites/apps that you have used Sign in with SimpleLogin
@@ -29,12 +29,15 @@
Info
+ title="Info this app/website receives">
|
-
+ |
First used
+ title="The first time you have used the 'Sign in with SimpleLogin' button on this app/website">
+ |
+
+ Actions
|
@@ -58,10 +61,18 @@
{% endfor %}
-
+ |
{{ client_user.created_at | dt }}
|
+
+
+ |
{% endfor %}
diff --git a/app/dashboard/views/app.py b/app/dashboard/views/app.py
index ad3f7517..0c881ee5 100644
--- a/app/dashboard/views/app.py
+++ b/app/dashboard/views/app.py
@@ -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,