mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Adding user deletion from admin panel
This commit is contained in:
@@ -286,6 +286,14 @@ def init_admin(app):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect('/scoreboard')
|
return redirect('/scoreboard')
|
||||||
|
|
||||||
|
@app.route('/admin/team/<teamid>/delete', methods=['POST'])
|
||||||
|
@admins_only
|
||||||
|
def delete_team(teamid):
|
||||||
|
user = Teams.query.filter_by(id=teamid).first()
|
||||||
|
db.session.delete(user)
|
||||||
|
db.session.commit()
|
||||||
|
return '1'
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin/graphs/<graph_type>')
|
@app.route('/admin/graphs/<graph_type>')
|
||||||
@admins_only
|
@admins_only
|
||||||
|
|||||||
@@ -5,8 +5,20 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<br>
|
<br>
|
||||||
|
<div id="confirm" class="reveal-modal" data-reveal>
|
||||||
|
<h2 class="text-center">Delete User</h2>
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="id">
|
||||||
|
<input type="hidden" name="nonce" value="{{ nonce }}">
|
||||||
|
<div class="small-6 small-centered text-center columns">
|
||||||
|
<p>Are you sure you want to delete <strong id="confirm-team-name"></strong>?</p>
|
||||||
|
<button type="button" class="button alert radius" onclick="$('#confirm').foundation('reveal', 'close');">No</button>
|
||||||
|
<button type="button" id="delete-user" class="button success radius">Yes</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<div id="user" class="reveal-modal" data-reveal>
|
<div id="user" class="reveal-modal" data-reveal>
|
||||||
<h2>Edit User</h2>
|
<h2 class="text-center">Edit User</h2>
|
||||||
<form method="POST" action="/admin/teams/">
|
<form method="POST" action="/admin/teams/">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<input type="hidden" name="nonce" value="{{ nonce }}">
|
<input type="hidden" name="nonce" value="{{ nonce }}">
|
||||||
@@ -97,7 +109,7 @@
|
|||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function load_modal(id, name, email, website, affiliation, country){
|
function load_update_modal(id, name, email, website, affiliation, country){
|
||||||
var modal_form = $('#user form');
|
var modal_form = $('#user form');
|
||||||
|
|
||||||
modal_form.find('input[name=name]').val(name)
|
modal_form.find('input[name=name]').val(name)
|
||||||
@@ -132,7 +144,19 @@ $('#update-user').click(function(e){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
|
|
||||||
|
$('#delete-user').click(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
var id = $('#confirm input[name="id"]').val()
|
||||||
|
var user_data = $('#confirm form').serializeArray()
|
||||||
|
$.post($('#confirm form').attr('action'), $('#confirm form').serialize(), function(data){
|
||||||
|
var data = $.parseJSON(JSON.stringify(data))
|
||||||
|
if (data == "1"){
|
||||||
|
location.reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
$('.fa-pencil-square-o').click(function(){
|
$('.fa-pencil-square-o').click(function(){
|
||||||
var elem = $(this).parent().parent().parent();
|
var elem = $(this).parent().parent().parent();
|
||||||
@@ -143,7 +167,23 @@ $('.fa-pencil-square-o').click(function(){
|
|||||||
var affiliation = elem.find('.team-affiliation').text().trim();
|
var affiliation = elem.find('.team-affiliation').text().trim();
|
||||||
var country = elem.find('.team-country').text().trim();
|
var country = elem.find('.team-country').text().trim();
|
||||||
|
|
||||||
load_modal(id, name, email, website, affiliation, country);
|
load_update_modal(id, name, email, website, affiliation, country);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function load_confirm_modal(id, name){
|
||||||
|
var modal = $('#confirm')
|
||||||
|
modal.find('input[name=id]').val(id)
|
||||||
|
modal.find('#confirm-team-name').text(name)
|
||||||
|
$('#confirm form').attr('action', '/admin/team/'+id+'/delete');
|
||||||
|
$('#confirm').foundation('reveal', 'open');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.fa-times').click(function(){
|
||||||
|
var elem = $(this).parent().parent().parent();
|
||||||
|
var id = elem.find('.team-id').text().trim();
|
||||||
|
var name = elem.find('.team-name').text().trim();
|
||||||
|
load_confirm_modal(id, name)
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user