MCPcopy Create free account
hub / github.com/BruceDevices/firmware / checkUserWebAuth

Function checkUserWebAuth

src/core/wifi/webInterface.cpp:170–189  ·  view source on GitHub ↗

** Function: checkUserWebAuth ** used by server->on functions to discern whether a user has the correct ** httpapitoken OR is authenticated by username and password **********************************************************************/

Source from the content-addressed store, hash-verified

168** httpapitoken OR is authenticated by username and password
169**********************************************************************/
170bool checkUserWebAuth(AsyncWebServerRequest *request, bool onFailureReturnLoginPage = false) {
171 if (request->hasHeader("Cookie")) {
172 const AsyncWebHeader *cookie = request->getHeader("Cookie");
173 String c = cookie->value();
174 int idx = c.indexOf("BRUCESESSION=");
175 if (idx != -1) {
176 int start = idx + 13;
177 int end = c.indexOf(';', start);
178 if (end == -1) end = c.length();
179 String token = c.substring(start, end);
180 if (bruceConfig.isValidWebUISession(token)) { return true; }
181 }
182 }
183 if (onFailureReturnLoginPage) {
184 serveWebUIFile(request, "login.html", "text/html", true, login_html, login_html_size);
185 } else {
186 request->send(401, "text/plain", "Unauthorized");
187 }
188 return false;
189}
190
191/**********************************************************************
192** Function: createDirRecursive

Callers 2

handleUploadFunction · 0.85
configureWebServerFunction · 0.85

Calls 2

serveWebUIFileFunction · 0.85
isValidWebUISessionMethod · 0.80

Tested by

no test coverage detected