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

32
web/shared/admin/admin.go Normal file
View File

@@ -0,0 +1,32 @@
package admin
import (
"context"
"mal/internal/db"
)
type contextKey string
const userContextKey contextKey = "user"
const AdminEmail = "mikkelelvers@outlook.com"
func IsAdmin(user *database.User) bool {
if user == nil {
return false
}
return user.Username == AdminEmail
}
func GetUser(ctx context.Context) *database.User {
user, ok := ctx.Value(userContextKey).(*database.User)
if !ok {
return nil
}
return user
}
func IsAdminFromContext(ctx context.Context) bool {
return IsAdmin(GetUser(ctx))
}