package server import ( "net/http" "git.lohmar.co.uk/cclohmar/NextMyDay/internal/core/recovery" ) // recoveryModule is the `do` module carrying the SPEC-007 approve/deny actions. // It rides a GUID path, so the door session-gates it (unlike the anonymous // `auth` recover action). const recoveryModule = "recovery" // RegisterRecoveryFlow registers SPEC-007's surface: // // - the core `access` workflow (GET /access — the anonymous recovery entry), // - the `auth` module's `recover` action (POST /access?do=auth&action=recover, // anonymous, A15), and // - the session-gated `recovery` approve/deny actions // (POST /{GUID}?do=recovery&action=approve|deny). func RegisterRecoveryFlow(reg *MapRegistry, a *recovery.Actions) { reg.RegisterCore("access", adaptRecovery(a.Page)) // The recovery request rides the `auth` action module, exactly as SPEC-007 // §4 spells it: POST /access?do=auth&action=recover. The module may already // exist (SPEC-006's enroll/login); extend it rather than replace it. auth := reg.module(authModule) if auth == nil { auth = NewModule(authModule) reg.RegisterModule(auth) } auth.AddAction("recover", "recover.request", adaptRecovery(a.Request)) reg.RegisterModule(NewModule(recoveryModule). AddAction("approve", "approve", adaptRecoveryActor(a.Approve)). AddAction("deny", "deny", adaptRecoveryActor(a.Deny))) } // adaptRecovery adapts an anonymous recovery handler to the door's Handler. func adaptRecovery(f func(http.ResponseWriter, *http.Request) error) Handler { return func(w http.ResponseWriter, r *http.Request, _ *RequestContext) error { return f(w, r) } } // adaptRecoveryActor adapts a session-gated decision handler: the door has // authenticated the actor and put its id on the RequestContext. func adaptRecoveryActor(f func(http.ResponseWriter, *http.Request, int64) error) Handler { return func(w http.ResponseWriter, r *http.Request, rc *RequestContext) error { return f(w, r, rc.UserID) } }