2026-01-05 11:24:23 -05:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
2026-01-07 12:38:31 -05:00
|
|
|
"nebula/models"
|
2026-01-05 11:24:23 -05:00
|
|
|
"nebula/views"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func RegisterRoutes(mux *http.ServeMux) {
|
|
|
|
|
mux.HandleFunc("GET /", handleWelcome)
|
|
|
|
|
mux.HandleFunc("GET /welcome", handleWelcome)
|
|
|
|
|
mux.HandleFunc("GET /welcome/step/{step}", handleWelcomeStep)
|
2026-01-05 13:34:44 -05:00
|
|
|
|
|
|
|
|
mux.HandleFunc("GET /register", handleRegister)
|
|
|
|
|
mux.HandleFunc("GET /register/step/{step}", handleRegisterStep)
|
|
|
|
|
mux.HandleFunc("GET /register/capabilities", handleRegisterCapabilities)
|
|
|
|
|
mux.HandleFunc("POST /register/verify-code", handleRegisterVerifyCode)
|
2026-01-05 13:44:02 -05:00
|
|
|
|
|
|
|
|
mux.HandleFunc("GET /login", handleLogin)
|
|
|
|
|
mux.HandleFunc("GET /login/step/{step}", handleLoginStep)
|
|
|
|
|
mux.HandleFunc("GET /login/qr-status", handleLoginQRStatus)
|
2026-01-05 13:57:11 -05:00
|
|
|
|
|
|
|
|
mux.HandleFunc("GET /authorize", handleAuthorize)
|
|
|
|
|
mux.HandleFunc("POST /authorize/approve", handleAuthorizeApprove)
|
|
|
|
|
mux.HandleFunc("POST /authorize/deny", handleAuthorizeDeny)
|
|
|
|
|
|
|
|
|
|
mux.HandleFunc("GET /dashboard", handleDashboard)
|
2026-01-07 12:38:31 -05:00
|
|
|
|
|
|
|
|
mux.HandleFunc("GET /settings", handleSettings)
|
2026-01-05 11:24:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleWelcome renders the full welcome page at step 1
|
|
|
|
|
func handleWelcome(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
views.WelcomePage(1).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleWelcomeStep handles HTMX partial updates for step navigation
|
|
|
|
|
func handleWelcomeStep(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
stepStr := r.PathValue("step")
|
|
|
|
|
step, err := strconv.Atoi(stepStr)
|
|
|
|
|
if err != nil || step < 1 || step > 3 {
|
|
|
|
|
step = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if this is an HTMX request
|
|
|
|
|
if r.Header.Get("HX-Request") == "true" {
|
2026-01-05 13:28:41 -05:00
|
|
|
// Return step content with OOB stepper update (HTMX 4 pattern)
|
|
|
|
|
views.WelcomeStepWithStepper(step).Render(r.Context(), w)
|
2026-01-05 11:24:23 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
views.WelcomePage(step).Render(r.Context(), w)
|
|
|
|
|
}
|
2026-01-05 13:34:44 -05:00
|
|
|
|
|
|
|
|
func handleRegister(w http.ResponseWriter, r *http.Request) {
|
2026-01-07 12:38:31 -05:00
|
|
|
state := models.RegisterState{Step: 1}
|
2026-01-05 13:34:44 -05:00
|
|
|
views.RegisterPage(state).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleRegisterStep(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
stepStr := r.PathValue("step")
|
|
|
|
|
step, err := strconv.Atoi(stepStr)
|
|
|
|
|
if err != nil || step < 1 || step > 3 {
|
|
|
|
|
step = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
method := r.URL.Query().Get("method")
|
|
|
|
|
if method == "" {
|
|
|
|
|
method = "passkey"
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 12:38:31 -05:00
|
|
|
state := models.RegisterState{Step: step, Method: method}
|
2026-01-05 13:34:44 -05:00
|
|
|
|
|
|
|
|
if r.Header.Get("HX-Request") == "true" {
|
|
|
|
|
views.RegisterStepWithStepper(state).Render(r.Context(), w)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
views.RegisterPage(state).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleRegisterCapabilities(w http.ResponseWriter, r *http.Request) {
|
2026-01-07 12:38:31 -05:00
|
|
|
caps := models.DeviceCapabilities{
|
2026-01-05 13:34:44 -05:00
|
|
|
Platform: true,
|
|
|
|
|
CrossPlatform: true,
|
|
|
|
|
Conditional: true,
|
|
|
|
|
}
|
|
|
|
|
views.CapabilitiesResult(caps).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleRegisterVerifyCode(w http.ResponseWriter, r *http.Request) {
|
2026-01-07 12:38:31 -05:00
|
|
|
state := models.RegisterState{Step: 3}
|
2026-01-05 13:34:44 -05:00
|
|
|
if r.Header.Get("HX-Request") == "true" {
|
|
|
|
|
views.RegisterStepWithStepper(state).Render(r.Context(), w)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
views.RegisterPage(state).Render(r.Context(), w)
|
|
|
|
|
}
|
2026-01-05 13:44:02 -05:00
|
|
|
|
|
|
|
|
func handleLogin(w http.ResponseWriter, r *http.Request) {
|
2026-01-07 12:38:31 -05:00
|
|
|
state := models.LoginState{Step: "1"}
|
2026-01-05 13:44:02 -05:00
|
|
|
views.LoginPage(state).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleLoginStep(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
step := r.PathValue("step")
|
|
|
|
|
if step == "" {
|
|
|
|
|
step = "1"
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 12:38:31 -05:00
|
|
|
state := models.LoginState{Step: step}
|
2026-01-05 13:44:02 -05:00
|
|
|
|
|
|
|
|
if r.Header.Get("HX-Request") == "true" {
|
|
|
|
|
views.LoginStepWithOOB(state).Render(r.Context(), w)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
views.LoginPage(state).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var qrPollCount = 0
|
|
|
|
|
|
|
|
|
|
func handleLoginQRStatus(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
qrPollCount++
|
|
|
|
|
if qrPollCount >= 3 {
|
|
|
|
|
qrPollCount = 0
|
|
|
|
|
views.QRStatusSuccess().Render(r.Context(), w)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
views.QRStatusWaiting().Render(r.Context(), w)
|
|
|
|
|
}
|
2026-01-05 13:57:11 -05:00
|
|
|
|
|
|
|
|
func handleAuthorize(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
reqType := r.URL.Query().Get("type")
|
2026-01-07 12:38:31 -05:00
|
|
|
req := models.DefaultAuthRequest(reqType)
|
2026-01-05 13:57:11 -05:00
|
|
|
views.AuthorizePage(req).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleAuthorizeApprove(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
r.ParseForm()
|
|
|
|
|
actionType := r.FormValue("type")
|
|
|
|
|
if actionType == "" {
|
|
|
|
|
actionType = "connect"
|
|
|
|
|
}
|
|
|
|
|
views.AuthResultSuccess(actionType).Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleAuthorizeDeny(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
views.AuthResultDenied().Render(r.Context(), w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleDashboard(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
tab := r.URL.Query().Get("tab")
|
|
|
|
|
if tab == "" {
|
2026-01-05 15:39:40 -05:00
|
|
|
tab = "overview"
|
2026-01-05 13:57:11 -05:00
|
|
|
}
|
2026-01-07 12:38:31 -05:00
|
|
|
data := models.DefaultDashboardData()
|
2026-01-05 18:41:05 -05:00
|
|
|
|
|
|
|
|
if r.Header.Get("HX-Request") == "true" {
|
|
|
|
|
views.DashboardContent(data, tab).Render(r.Context(), w)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-05 13:57:11 -05:00
|
|
|
views.DashboardPage(data, tab).Render(r.Context(), w)
|
|
|
|
|
}
|
2026-01-07 12:38:31 -05:00
|
|
|
|
|
|
|
|
func handleSettings(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
tab := r.URL.Query().Get("tab")
|
|
|
|
|
if tab == "" {
|
|
|
|
|
tab = "profile"
|
|
|
|
|
}
|
|
|
|
|
data := models.DefaultSettingsData()
|
|
|
|
|
views.SettingsPage(data, tab).Render(r.Context(), w)
|
|
|
|
|
}
|