| 459 | } |
| 460 | |
| 461 | esp_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 | |
| 485 | esp_err_t logoutHandler(httpd_req_t *req) { |
| 486 | ensurePersistedSessionLoaded(); |
nothing calls this directly
no test coverage detected