From 185262b2e771dc012a28b6b2d7e2212ad346331b Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 16 Feb 2018 11:42:41 +0100 Subject: [PATCH] admin: introducing new page --- main.go | 9 +++++++++ static/admin.html | 23 +++++++++++++++++++++++ static/js/youp0m-admin.js | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 static/admin.html create mode 100644 static/js/youp0m-admin.js diff --git a/main.go b/main.go index f0b2d4f..2288d64 100644 --- a/main.go +++ b/main.go @@ -91,6 +91,15 @@ func main() { GetNextImage, ))) + mux.HandleFunc("/admin/", func(w http.ResponseWriter, r *http.Request) { + if authFunc(r) == nil { + w.Header().Set("WWW-Authenticate", "Basic realm=\"YouP0m Admin\"") + http.Error(w, "You are not allowed to perform this request.", http.StatusUnauthorized) + } else { + http.ServeFile(w, r, filepath.Join(staticDir, "admin.html")) + } + }) + log.Println("Ready, listening on", *bind) if err := http.ListenAndServe(*bind, mux); err != nil { log.Fatal("Unable to listen and serve: ", err) diff --git a/static/admin.html b/static/admin.html new file mode 100644 index 0000000..c1b1445 --- /dev/null +++ b/static/admin.html @@ -0,0 +1,23 @@ + + + + YouP0m Administration + + + + + + + +

Welcome on YouP0m!

+ + + + diff --git a/static/js/youp0m-admin.js b/static/js/youp0m-admin.js new file mode 100644 index 0000000..43f3341 --- /dev/null +++ b/static/js/youp0m-admin.js @@ -0,0 +1,17 @@ +api_url = "/api/next/"; +img_url = "/images/next/"; + +function admin_ctrl(figure) { + var menu = document.createElement("ul"); + var item = document.createElement("li", "test"); + menu.appendChild(item); + figure.appendChild(menu) +} + +function sync() { + path = window.location.pathname.replace(/.*\/([^\/]*)/, "$1"); + if (path == "" || path == "all") + show_mozaic(admin_ctrl); + else + show_picture(path); +}