patch: fixed admin panel
This commit is contained in:
parent
afc42b2991
commit
f46ef4b4fe
2 changed files with 53 additions and 11 deletions
|
|
@ -118,6 +118,7 @@ func main() {
|
||||||
http.HandleFunc("/api/logout", handleLogout)
|
http.HandleFunc("/api/logout", handleLogout)
|
||||||
http.HandleFunc("/api/comics", authMiddleware(handleComics))
|
http.HandleFunc("/api/comics", authMiddleware(handleComics))
|
||||||
http.HandleFunc("/api/upload", authMiddleware(handleUpload))
|
http.HandleFunc("/api/upload", authMiddleware(handleUpload))
|
||||||
|
http.HandleFunc("/api/user", authMiddleware(handleUser))
|
||||||
http.HandleFunc("/api/organize", authMiddleware(handleOrganize))
|
http.HandleFunc("/api/organize", authMiddleware(handleOrganize))
|
||||||
http.HandleFunc("/api/pages/", authMiddleware(handleComicPages))
|
http.HandleFunc("/api/pages/", authMiddleware(handleComicPages))
|
||||||
http.HandleFunc("/api/comic/", authMiddleware(handleComicFile))
|
http.HandleFunc("/api/comic/", authMiddleware(handleComicFile))
|
||||||
|
|
@ -209,6 +210,21 @@ func handleToggleRegistration(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]bool{"enabled": registrationEnabled})
|
json.NewEncoder(w).Encode(map[string]bool{"enabled": registrationEnabled})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleUser(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := getCurrentUser(r)
|
||||||
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
|
"username": user.Username,
|
||||||
|
"is_admin": user.IsAdmin,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func getCurrentUser(r *http.Request) User {
|
func getCurrentUser(r *http.Request) User {
|
||||||
cookie, err := r.Cookie("session")
|
cookie, err := r.Cookie("session")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -1797,18 +1797,44 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch('/api/comics')
|
fetch('/api/user')
|
||||||
.then(function(res) {
|
.then(function(res) {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
document.getElementById('authSection').classList.add('hidden');
|
return res.json();
|
||||||
document.getElementById('mainSection').classList.remove('hidden');
|
}
|
||||||
document.getElementById('userInfo').classList.remove('hidden');
|
})
|
||||||
loadTags().then(loadComics);
|
.then(function(data) {
|
||||||
|
if (data) {
|
||||||
|
window.isAdmin = data.is_admin || false;
|
||||||
|
if (window.isAdmin) {
|
||||||
|
fetch('/api/admin/toggle-registration')
|
||||||
|
.then(function(adminRes) {
|
||||||
|
if (adminRes.ok) return adminRes.json();
|
||||||
|
})
|
||||||
|
.then(function(adminData) {
|
||||||
|
if (adminData) {
|
||||||
|
window.registrationEnabled = adminData.enabled;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.catch(function(err) {
|
})
|
||||||
console.error('Initial comics fetch failed:', err);
|
.catch(function(err) {
|
||||||
});
|
console.error('User fetch failed:', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
fetch('/api/comics')
|
||||||
|
.then(function(res) {
|
||||||
|
if (res.ok) {
|
||||||
|
document.getElementById('authSection').classList.add('hidden');
|
||||||
|
document.getElementById('mainSection').classList.remove('hidden');
|
||||||
|
document.getElementById('userInfo').classList.remove('hidden');
|
||||||
|
loadTags().then(loadComics);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.error('Initial comics fetch failed:', err);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue