MCPcopy Create free account
hub / github.com/bmorcelli/Launcher / loginHandler

Function loginHandler

src/webInterface.cpp:461–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

459}
460
461esp_err_t loginHandler(httpd_req_t *req) {
462 WebParamMap params = readParams(req);
463 if (params.has("username") && params.has("password") && params.get("username") == wui_usr &&
464 params.get("password") == wui_pwd) {
465 String token = generateToken();
466 sessions.clear();
467 sessions[token] = launcherMillis();
468 saveSessionToken(token);
469 sessionTokenLoaded = true;
470 persistedSessionToken = token;
471
472 // Keep cookie string alive until after httpd_resp_send — httpd_resp_set_hdr
473 // stores raw pointers without copying, so a temporary String would dangle.
474 String cookieHeader = "ESP32SESSION=" + token + "; Path=/; HttpOnly";
475 httpd_resp_set_status(req, "302 Found");
476 httpd_resp_set_hdr(req, "Location", "/");
477 httpd_resp_set_hdr(req, "Set-Cookie", cookieHeader.c_str());
478 httpd_resp_send(req, nullptr, 0);
479 return ESP_OK;
480 }
481 redirectTo(req, "/?failed");
482 return ESP_OK;
483}
484
485esp_err_t logoutHandler(httpd_req_t *req) {
486 ensurePersistedSessionLoaded();

Callers

nothing calls this directly

Calls 8

readParamsFunction · 0.85
launcherMillisFunction · 0.85
saveSessionTokenFunction · 0.85
redirectToFunction · 0.85
hasMethod · 0.80
getMethod · 0.80
generateTokenFunction · 0.70
clearMethod · 0.45

Tested by

no test coverage detected