added confirmation dialog before deleting token
This commit is contained in:
parent
62321d8b3c
commit
f9eadc3c5a
8
app.py
8
app.py
|
@ -45,7 +45,6 @@ class Role(db.Model, fsqla.FsRoleMixin):
|
||||||
|
|
||||||
class User(db.Model, fsqla.FsUserMixin):
|
class User(db.Model, fsqla.FsUserMixin):
|
||||||
username = db.Column(db.String(255))
|
username = db.Column(db.String(255))
|
||||||
pass
|
|
||||||
|
|
||||||
class ExtendedLoginForm(LoginForm):
|
class ExtendedLoginForm(LoginForm):
|
||||||
email = StringField('Benutzername oder E-Mail', [Required()])
|
email = StringField('Benutzername oder E-Mail', [Required()])
|
||||||
|
@ -200,9 +199,9 @@ def store_token():
|
||||||
return redirect('/tokens')
|
return redirect('/tokens')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/delete-token/<token>')
|
@app.route('/delete-token', methods=['POST'])
|
||||||
#@auth_required()
|
#@auth_required()
|
||||||
def delete_token(token):
|
def delete_token():
|
||||||
"""Delete the given token from the token file and store the new token file to disk
|
"""Delete the given token from the token file and store the new token file to disk
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
@ -210,11 +209,12 @@ def delete_token(token):
|
||||||
token : str
|
token : str
|
||||||
The token to delete from the database.
|
The token to delete from the database.
|
||||||
"""
|
"""
|
||||||
|
token = request.form.get('token')
|
||||||
tokens = door.get_tokens()
|
tokens = door.get_tokens()
|
||||||
if token in tokens: # check if token exists
|
if token in tokens: # check if token exists
|
||||||
tokens.pop(token)
|
tokens.pop(token)
|
||||||
door.store_tokens(tokens)
|
door.store_tokens(tokens)
|
||||||
return redirect('/tokens')
|
return "success"
|
||||||
|
|
||||||
|
|
||||||
@app.route('/deactivate-token/<token>')
|
@app.route('/deactivate-token/<token>')
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Tokens</title>
|
<title>Tokens</title>
|
||||||
|
|
||||||
|
<script src="../static/jquery-3.6.0.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% with messages = get_flashed_messages() %}
|
{% with messages = get_flashed_messages() %}
|
||||||
|
@ -30,7 +32,7 @@
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ url_for('edit_token', token=t) }}"><img src="static/edit.png" title="Editieren" alt="Edit"></a>
|
<a href="{{ url_for('edit_token', token=t) }}"><img src="static/edit.png" title="Editieren" alt="Edit"></a>
|
||||||
<a href="{{ url_for('deactivate_token', token=t) }}"><img src="static/stop.png" title="Deaktivieren" alt="Deactivate"></a>
|
<a href="{{ url_for('deactivate_token', token=t) }}"><img src="static/stop.png" title="Deaktivieren" alt="Deactivate"></a>
|
||||||
<a href="{{ url_for('delete_token', token=t) }}"><img src="static/delete.png" title="Löschen" alt="Delete"></a>
|
<img src="static/delete.png" title="Löschen" alt="Delete" onclick="confirmDelete('{{ t }}')">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -42,11 +44,26 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ url_for('edit_token', token=t) }}"><img src="static/edit.png" title="Editieren" alt="Edit"></a>
|
<a href="{{ url_for('edit_token', token=t) }}"><img src="static/edit.png" title="Editieren" alt="Edit"></a>
|
||||||
<a href="{{ url_for('delete_token', token=t) }}"><img src="static/delete.png" title="Löschen" alt="Delete"></a>
|
<img src="static/delete.png" title="Löschen" alt="Delete" onclick="confirmDelete('{{ t }}')">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
<script>
|
||||||
|
function confirmDelete(t) {
|
||||||
|
debugger
|
||||||
|
if (confirm('Token wirklich löschen?')) {
|
||||||
|
console.log('confirmed');
|
||||||
|
console.log(t);
|
||||||
|
$.post('{{ url_for('delete_token') }}', {token: t},
|
||||||
|
function (data) {
|
||||||
|
if (data === 'success') {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user