1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Implemented admin mode

This commit is contained in:
Krateng 2019-11-20 05:19:02 +01:00
parent 204712e240
commit 9b7bc5e38e
4 changed files with 77 additions and 5 deletions

11
info.py
View File

@ -1 +1,10 @@
version = 1,5,11
import os
author = {
"name":"Johannes Krattenmacher",
"email":"maloja@krateng.dev",
"github": "krateng"
}
version = 1,5,12
versionstr = ".".join(str(n) for n in version)
dev = os.path.exists("./.dev")

View File

@ -153,12 +153,16 @@ def static_html(name):
html_file = os.path.exists("website/" + name + ".html")
pyhp_pref = settings.get_settings("USE_PYHP")
adminmode = request.cookies.get("adminmode") == "true" and database.checkAPIkey(request.cookies.get("apikey")) is not False
# if a pyhp file exists, use this
if (pyhp_file and pyhp_pref) or (pyhp_file and not html_file):
from doreah.pyhp import file
environ = {} #things we expose to the pyhp pages
environ["adminmode"] = adminmode
# maloja
environ["db"] = database
environ["htmlmodules"] = htmlmodules

View File

@ -31,7 +31,55 @@
}
});
});
function activate() {
neo.setCookie("adminmode","true");
window.location.reload(true);
}
function deactivate() {
neo.setCookie("adminmode","false");
window.location.reload(true);
}
function buttonlock() {
button = document.getElementById("adminmodebutton")
if (apikeycorrect) {
button.classList.remove("locked");
if (button.innerHTML == "Activate") { button.onclick = activate; }
else { button.onclick = deactivate; }
// ugh
}
else {
button.classList.add("locked");
button.onclick = null;
}
}
window.addEventListener("load",function(){checkAPIkey(buttonlock)});
// we do this twice, but this one ensures that the button is correctly locked / unlocked after the api key has been checked
</script>
<style>
.button {
padding:3px;
padding-right:6px;
padding-left:6px;
background-color:beige;
color:black;
cursor:pointer;
}
.button:hover {
background-color:gold;
}
.button:active {
background-color:orange;
}
.button.locked {
background-color:grey;
color:black;
cursor:not-allowed;
}
</style>
</head>
<body>
@ -45,9 +93,10 @@
<div style="background-image:url('/favicon.png')"></div>
</td>
<td class="text">
<h1>Maloja</h1><br/>
<h1>Admin Panel</h1><br/>
<br/><br/>
API Key: <input id='apikey' onchange='checkAPIkey(buttonlock);' style='width:300px;'/><br/><br/>
<p class="desc">Welcome to your own Maloja server!</p>
</td>
</tr>
</table>
@ -61,7 +110,9 @@
<h2>Admin Mode</h2>
Activate admin mode to manually scrobble from various places on the website (Coming soon)
Admin Mode allows you to manually scrobble from various places on the web interface instead of just the dedicated page.<br/><br/>
<pyhp if="adminmode"><span id="adminmodebutton" class="button locked">Deactivate</span></pyhp>
<pyhp if="not adminmode"><span id="adminmodebutton" class="button locked">Activate</span></pyhp>
<h2>Links</h2>

View File

@ -67,7 +67,7 @@ function saveAPIkey() {
function checkAPIkey() {
function checkAPIkey(extrafunc=null) {
url = "/api/test?key=" + APIkey()
var xhttp = new XMLHttpRequest();
@ -81,6 +81,11 @@ function checkAPIkey() {
document.getElementById("apikey").style.backgroundColor = "red"
apikeycorrect = false
}
if (extrafunc != null) {
extrafunc();
}
};
try {
xhttp.open("GET",url,true);
@ -89,6 +94,9 @@ function checkAPIkey() {
catch (e) {
document.getElementById("apikey").style.backgroundColor = "red"
apikeycorrect = false
if (extrafunc != null) {
extrafunc();
}
}
}