diff --git a/CTFd/admin/pages.py b/CTFd/admin/pages.py index b698dd3..9751faa 100644 --- a/CTFd/admin/pages.py +++ b/CTFd/admin/pages.py @@ -19,24 +19,27 @@ def admin_css(): return '0' -@admin_pages.route('/admin/pages', defaults={'route': None}, methods=['GET', 'POST']) -@admin_pages.route('/admin/pages/', methods=['GET', 'POST']) +@admin_pages.route('/admin/pages', methods=['GET', 'POST']) @admins_only -def admin_pages_view(route): +def admin_pages_view(): + route = request.args.get('route') + if request.method == 'GET' and request.args.get('mode') == 'create': return render_template('admin/editor.html') + if route and request.method == 'GET': page = Pages.query.filter_by(route=route).first() return render_template('admin/editor.html', page=page) - if route and request.method == 'POST': + + if request.method == 'POST': + html = request.form['html'] + route = request.form['route'].lstrip('/') page = Pages.query.filter_by(route=route).first() errors = [] - html = request.form['html'] - route = request.form['route'] if not route: errors.append('Missing URL route') if errors: - page = Pages(html, '') + page = Pages(html, route) return render_template('/admin/editor.html', page=page) if page: page.route = route @@ -53,10 +56,24 @@ def admin_pages_view(route): with app.app_context(): cache.clear() return redirect(url_for('admin_pages.admin_pages_view')) + pages = Pages.query.all() return render_template('admin/pages.html', routes=pages, css=utils.get_config('css')) +@admin_pages.route('/admin/pages/delete', methods=['POST']) +@admins_only +def delete_page(): + route = request.form['route'] + page = Pages.query.filter_by(route=route).first_or_404() + db.session.delete(page) + db.session.commit() + db.session.close() + with app.app_context(): + cache.clear() + return '1' + + @admin_pages.route('/admin/media', methods=['GET', 'POST', 'DELETE']) @admins_only def admin_pages_media(): @@ -77,15 +94,3 @@ def admin_pages_media(): else: files = [{'id': f.id, 'location': f.location} for f in Files.query.filter_by(chal=None).all()] return jsonify({'results': files}) - - -@admin_pages.route('/admin/page//delete', methods=['POST']) -@admins_only -def delete_page(pageroute): - page = Pages.query.filter_by(route=pageroute).first_or_404() - db.session.delete(page) - db.session.commit() - db.session.close() - with app.app_context(): - cache.clear() - return '1' diff --git a/CTFd/themes/admin/templates/editor.html b/CTFd/themes/admin/templates/editor.html index 6b773aa..30e5b14 100644 --- a/CTFd/themes/admin/templates/editor.html +++ b/CTFd/themes/admin/templates/editor.html @@ -272,7 +272,7 @@ }); $('#page-edit').submit(function (e){ - $(this).attr('action', '{{ request.script_root }}/admin/pages/'+$('#route').val()); + $(this).attr('action', '{{ request.script_root }}/admin/pages'); }); // Markdown Preview diff --git a/CTFd/themes/admin/templates/pages.html b/CTFd/themes/admin/templates/pages.html index c6d2544..bb257b5 100644 --- a/CTFd/themes/admin/templates/pages.html +++ b/CTFd/themes/admin/templates/pages.html @@ -51,7 +51,7 @@ {% for route in routes %} {{ route.route }} + href="{{ request.script_root }}/admin/pages?route={{ route.route }}">{{ route.route }} {% endfor %} @@ -103,7 +103,7 @@ function load_confirm_modal(route){ var modal = $('#confirm') modal.find('input[name=route]').val(route) modal.find('#confirm-route-name').text(route) - $('#confirm form').attr('action', '{{ request.script_root }}/admin/page/'+route+'/delete'); + $('#confirm form').attr('action', '{{ request.script_root }}/admin/pages/delete'); $('#confirm').modal(); } diff --git a/CTFd/views.py b/CTFd/views.py index 5f8bb91..953e38f 100644 --- a/CTFd/views.py +++ b/CTFd/views.py @@ -106,7 +106,7 @@ def custom_css(): # Static HTML files @views.route("/", defaults={'template': 'index'}) -@views.route("/