admin: add admin panel for user management

This commit is contained in:
2026-04-22 21:16:26 +02:00
parent 7e15380638
commit 77f0daca26
11 changed files with 530 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
package middleware
import (
"net/http"
"mal/internal/db"
"mal/web/shared/admin"
)
func IsAdmin(user *database.User) bool {
return admin.IsAdmin(user)
}
func RequireAdmin(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, ok := r.Context().Value(UserContextKey).(*database.User)
if !ok || user == nil {
http.Redirect(w, r, "/login", http.StatusFound)
return
}
if !admin.IsAdmin(user) {
http.Error(w, "Forbidden", http.StatusForbidden)
return
}
next.ServeHTTP(w, r)
})
}