feat(handlers): add register routes and handlers for user registration process
This commit is contained in:
@@ -11,6 +11,11 @@ func RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /", handleWelcome)
|
||||
mux.HandleFunc("GET /welcome", handleWelcome)
|
||||
mux.HandleFunc("GET /welcome/step/{step}", handleWelcomeStep)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// handleWelcome renders the full welcome page at step 1
|
||||
@@ -33,6 +38,50 @@ func handleWelcomeStep(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Full page render for non-HTMX requests
|
||||
views.WelcomePage(step).Render(r.Context(), w)
|
||||
}
|
||||
|
||||
func handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
state := views.RegisterState{Step: 1}
|
||||
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"
|
||||
}
|
||||
|
||||
state := views.RegisterState{Step: step, Method: method}
|
||||
|
||||
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) {
|
||||
caps := views.DeviceCapabilities{
|
||||
Platform: true,
|
||||
CrossPlatform: true,
|
||||
Conditional: true,
|
||||
}
|
||||
views.CapabilitiesResult(caps).Render(r.Context(), w)
|
||||
}
|
||||
|
||||
func handleRegisterVerifyCode(w http.ResponseWriter, r *http.Request) {
|
||||
state := views.RegisterState{Step: 3}
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
views.RegisterStepWithStepper(state).Render(r.Context(), w)
|
||||
return
|
||||
}
|
||||
views.RegisterPage(state).Render(r.Context(), w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user