feat: settings page with admin panel link for admins
This commit is contained in:
parent
22958d09e7
commit
3332bc3d59
1 changed files with 61 additions and 2 deletions
61
main.go
61
main.go
|
|
@ -225,6 +225,19 @@ func adminHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func settingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Header.Get("Remote-User")
|
||||
groups := r.Header.Get("Remote-Groups")
|
||||
isAdmin := strings.Contains(groups, "admins")
|
||||
|
||||
tmpl := template.Must(template.New("settings").Parse(settingsHTML))
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
tmpl.Execute(w, map[string]interface{}{
|
||||
"User": user,
|
||||
"IsAdmin": isAdmin,
|
||||
})
|
||||
}
|
||||
|
||||
// --- Templates ---
|
||||
|
||||
const landingPageHTML = `<!DOCTYPE html>
|
||||
|
|
@ -318,7 +331,7 @@ const launcherHTML = `<!DOCTYPE html>
|
|||
</header>
|
||||
<div class="user-banner">
|
||||
<span>Welcome, {{.User}}</span>
|
||||
{{if .IsAdmin}}<a href="/config">Admin Panel</a>{{end}}
|
||||
<a href="/settings">⚙ Settings</a>
|
||||
<a href="https://auth.nextwks.eu/logout">Logout</a>
|
||||
</div>
|
||||
<div class="grid">
|
||||
|
|
@ -337,6 +350,48 @@ const launcherHTML = `<!DOCTYPE html>
|
|||
</body>
|
||||
</html>`
|
||||
|
||||
const settingsHTML = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Settings — NextWorkspace</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f2f5; color: #1a1a2e; }
|
||||
header { background: linear-gradient(135deg, #1a1a2e, #16213e); color: #fff; padding: 1.5rem 2rem; display: flex; justify-content: space-between; align-items: center; }
|
||||
header h1 { font-size: 1.5rem; }
|
||||
header a { color: #63b3ed; text-decoration: none; font-size: 0.9rem; }
|
||||
.container { max-width: 800px; margin: 0 auto; padding: 2rem; }
|
||||
.card { background: #fff; border-radius: 8px; padding: 1.5rem; margin-bottom: 1rem; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
|
||||
.card h2 { font-size: 1.1rem; margin-bottom: 0.5rem; color: #2d3748; }
|
||||
.card p { color: #718096; font-size: 0.9rem; }
|
||||
.card a { display: inline-block; margin-top: 0.5rem; color: #63b3ed; text-decoration: none; }
|
||||
.card a:hover { text-decoration: underline; }
|
||||
.badge { display: inline-block; background: #edf2f7; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.8rem; margin-right: 0.25rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Settings</h1>
|
||||
<a href="/home/">Back to Launcher</a>
|
||||
</header>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<h2>Account</h2>
|
||||
<p>Logged in as <strong>{{.User}}</strong></p>
|
||||
</div>
|
||||
{{if .IsAdmin}}
|
||||
<div class="card">
|
||||
<h2>Administration</h2>
|
||||
<p>Manage users, groups, and workspace configuration.</p>
|
||||
<a href="/config">⚖ Admin Panel →</a>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</body>
|
||||
</html>`
|
||||
|
||||
const adminHTML = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
|
@ -477,6 +532,10 @@ func main() {
|
|||
mux.Handle("/home/", authMiddleware(launcherHandler(cfg, apps)))
|
||||
mux.Handle("/home", authMiddleware(launcherHandler(cfg, apps)))
|
||||
|
||||
// Protected: settings
|
||||
mux.Handle("/settings", authMiddleware(settingsHandler))
|
||||
mux.Handle("/settings/", authMiddleware(settingsHandler))
|
||||
|
||||
// Protected: admin — admins only
|
||||
mux.Handle("/config", adminGroupMiddleware(authMiddleware(adminHandler)))
|
||||
mux.Handle("/config/", adminGroupMiddleware(authMiddleware(adminHandler)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue