Commit 39c5c9e0 authored by Vlad Dumitru's avatar Vlad Dumitru
Browse files

add admin panel

parent f3de9c5e
Pipeline #6816 failed with stages
in 2 minutes and 59 seconds
{% extends "base.html" %}
{% block content %}
<div class="container">
<h2>Administrator Actions</h2>
<form method="post" class="box flex col align-center justify-center">
<div class="row">
<label for="input-password">Password:</label>
<input type="password" name="password">
<div class="row">
<label for="check-reset-answers">Reset quiz answers</label>
<input type="checkbox" name="action" id="check-reset-answers" value="reset-answers">
<label for="check-delete-recordings">Delete recordings</label>
<input type="checkbox" name="action" id="check-delete-recordings" value="delete-recordings">
<div class="row">
<input type="submit" value="Submit">
{% endblock %}
{% block page-scripts %}
{% if = "audio" %}
window.addEventListener('load', () => {
const audioElement = document.getElementById('audio')
const playButton = document.getElementById('play-button')
playButton.addEventListener('click', () =>
{% endif %}
{% endblock %}
......@@ -51,3 +51,8 @@
(jdbc/query db)
(defn reset-answers []
(jdbc/delete! db :answer []))
(defn delete-recordings []
(jdbc/delete! db :recording []))
......@@ -10,6 +10,7 @@
[tunein.routes.home :refer [home-routes]]
[tunein.routes.quiz :refer [routes]]
[tunein.routes.record :refer [record-routes]]
[tunein.routes.admin :refer [admin-routes]]
[tunein.db.core :as db]))
(mount/defstate init-app
......@@ -20,7 +21,7 @@
[(home-routes) (routes) (record-routes)])
[(home-routes) (routes) (record-routes) (admin-routes)])
{:path "/"})
(ns tunein.routes.admin
[ :as io]
[ :as json]
[ring.util.response :refer [redirect]]
[ring.util.http-response :as response]
[reitit.ring :as ring]
[tunein.config :refer [env]]
[tunein.layout :as layout]
[tunein.middleware :as middleware]
[tunein.db.core :as db]))
(defn- render-admin-page [request]
(layout/render request "admin.html"))
(defn- perform [action]
(case action
"reset-answers" (db/reset-answers)
"delete-recordings" (db/delete-recordings)
{:status 400
:headers {"Content-Type" "text/plain"}
:body "unknown action type"}))
(defn- perform-admin-action [request]
(let [password (-> request :form-params (get "password"))
actions (-> request :form-params (get "action"))]
(if (= (env :admin-password) password)
(doall (map perform actions))
(redirect "/"))
{:status 403
:headers {"Content-Type" "text/plain"}
:body "wrong password"})))
(defn admin-routes []
["" {:get render-admin-page
:post perform-admin-action}]])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment