feat: reset dbs, load new dbs, disable buttons while processing
This commit is contained in:
parent
16fddcc24f
commit
0f6ebe1e58
@ -18,6 +18,7 @@ func main() {
|
||||
http.HandleFunc("/logout", validateSession(handleLogout, ""))
|
||||
|
||||
http.HandleFunc("/", validateSession(handleIndex, ""))
|
||||
http.HandleFunc("/database", validateSession(handleDatabase, ""))
|
||||
http.HandleFunc("/admin_panel", validateSession(handleAdminPanel, "admin"))
|
||||
// provide the inc directory to the useragent
|
||||
http.HandleFunc("/static/", validateSession(handleStatic, ""))
|
||||
@ -48,13 +49,24 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func handleAdminPanel(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
t, _ := getTemplate("layouts/base.html", "admin_panel.html", "header.html")
|
||||
t, _ := getTemplate("layouts/base.html", "soon.html", "header.html")
|
||||
currUser := r.Context().Value(currUserKey).(User)
|
||||
td := TmplData{currUser, nil}
|
||||
t.Execute(w, td)
|
||||
}
|
||||
}
|
||||
|
||||
func handleDatabase(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodPatch {
|
||||
currUser := r.Context().Value(currUserKey).(User)
|
||||
if createMariaDbDatabasesForUser(currUser.UID) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
t, _ := getTemplate("layouts/base.html", "register.html")
|
||||
|
@ -114,7 +114,8 @@ form {
|
||||
|
||||
#general-info {
|
||||
position: relative;
|
||||
bottom: 5px;
|
||||
box-sizing: border-box;
|
||||
bottom: -50px;
|
||||
margin-left: -165px;
|
||||
left: 50%;
|
||||
line-height: 40px;
|
||||
@ -125,6 +126,79 @@ form {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
/******************* HEADER *******************/
|
||||
|
||||
header {
|
||||
width: 400px;
|
||||
height: 30px;
|
||||
margin: auto;
|
||||
border-radius: 4px;
|
||||
background: var(--grey1);
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
nav {
|
||||
width: 90%;
|
||||
height: 100%;
|
||||
text-align: justify;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
nav:after {
|
||||
content: "";
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
nav * {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
color: var(--black);
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
nav > * {
|
||||
opacity: .7;
|
||||
}
|
||||
|
||||
nav > *:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
|
||||
}
|
||||
|
||||
.dropdown-main {
|
||||
}
|
||||
|
||||
.dropdown-sub {
|
||||
position: absolute;
|
||||
padding: 0 8px;
|
||||
z-index: 69;
|
||||
display: none;
|
||||
background: var(--grey1);
|
||||
border-radius: 0 0 4px 4px;
|
||||
filter: drop-shadow(-2px 2px 2px var(--grey2));
|
||||
}
|
||||
|
||||
.dropdown-sub > a {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.dropdown-sub > a:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.dropdown-sub > a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.dropdown:hover .dropdown-sub {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/******************* LOGIN *******************/
|
||||
|
||||
#frm-login, #frm-register {
|
||||
@ -144,3 +218,23 @@ form {
|
||||
margin-top: 15px;
|
||||
color: var(--black);
|
||||
}
|
||||
|
||||
/******************* MAIN *******************/
|
||||
|
||||
#wrapper {
|
||||
position: absolute;
|
||||
width: 500px;
|
||||
height: auto;
|
||||
|
||||
margin-left: -250px;
|
||||
left: 50%;
|
||||
top: 100px;
|
||||
|
||||
/* border: solid 2px blue; */
|
||||
}
|
||||
|
||||
#wrapper > button {
|
||||
position: relative;
|
||||
width: 80%;
|
||||
left: 10%;
|
||||
}
|
28
web/static/js/main.js
Normal file
28
web/static/js/main.js
Normal file
@ -0,0 +1,28 @@
|
||||
let rbtn = document.getElementById("btn-reset");
|
||||
let infoBox = document.getElementById("general-info");
|
||||
|
||||
rbtn.addEventListener("click", e => {
|
||||
e.preventDefault();
|
||||
|
||||
toggleDisabled(rbtn, "on");
|
||||
setInfo(infoBox, "Processing Request...", "purple", "grey1");
|
||||
toggleHidden(infoBox, "off");
|
||||
|
||||
fetch("/database", {
|
||||
method: "PATCH"
|
||||
}).then(res => {
|
||||
if (res.status == 200) {
|
||||
setInfo(infoBox, "Success", "green", "grey1");
|
||||
setTimeout(() => {
|
||||
toggleHidden(infoBox, "on");
|
||||
}, 2000);
|
||||
} else {
|
||||
setInfo(infoBox, "Failure", "red", "grey1");
|
||||
toggleHidden(infoBox, "off");
|
||||
setTimeout(() => {
|
||||
toggleHidden(infoBox, "on");
|
||||
}, 2000);
|
||||
}
|
||||
toggleDisabled(rbtn, "off");
|
||||
});
|
||||
});
|
@ -2,6 +2,7 @@
|
||||
<header>
|
||||
<nav>
|
||||
<a href="/">home</a>
|
||||
<a target="_blank" href="https://db.eeez.de">db.eeez.de</a>
|
||||
<a href="/admin_panel">admin</a>
|
||||
<a href="/logout">logout</a>
|
||||
</nav>
|
||||
|
@ -1,8 +1,11 @@
|
||||
{{define "body"}}
|
||||
<section id="wrapper">
|
||||
<button id="btn-reset">Reset & Refresh Databases</button>
|
||||
<div class="hidden" id="general-info"></div>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
<script src="/static/js/main.js"></script>
|
||||
<script src="/static/js/helper.js"></script>
|
||||
{{end}}
|
@ -4,7 +4,7 @@
|
||||
<input id="inp-email" name="email" type="email" value=""/>
|
||||
<label for="inp-secret">Registration-Key:</label>
|
||||
<input id="inp-secret" name="secret" type="password" value=""/>
|
||||
<button>Request User</button>
|
||||
<button id="btn-submit">Request User</button>
|
||||
</form>
|
||||
<div class="hidden" id="general-info"></div>
|
||||
{{end}}
|
||||
@ -12,10 +12,16 @@
|
||||
<script>
|
||||
let frm = document.getElementById("frm-register");
|
||||
let infoBox = document.getElementById("general-info");
|
||||
let sbtn = document.getElementById("btn-submit");
|
||||
|
||||
frm.addEventListener("submit", e => {
|
||||
e.preventDefault();
|
||||
let fd = new FormData(frm);
|
||||
|
||||
toggleDisabled(sbtn, "on");
|
||||
setInfo(infoBox, "Processing Request...", "purple", "grey1");
|
||||
toggleHidden(infoBox, "off");
|
||||
|
||||
fetch("/register", {
|
||||
method: "POST",
|
||||
body: new URLSearchParams({
|
||||
@ -29,7 +35,6 @@
|
||||
}).then(res => {
|
||||
if (res.status == 200) {
|
||||
setInfo(infoBox, "Success", "green", "grey1");
|
||||
toggleHidden(infoBox, "off");
|
||||
setTimeout(() => {
|
||||
toggleHidden(infoBox, "on");
|
||||
}, 2000);
|
||||
@ -40,7 +45,9 @@
|
||||
toggleHidden(infoBox, "on");
|
||||
}, 2000);
|
||||
}
|
||||
toggleDisabled(sbtn, "off");
|
||||
})
|
||||
|
||||
})
|
||||
</script>
|
||||
<script src="/static/js/helper.js"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user