diff --git a/include/aclwebserver.h b/include/aclwebserver.h index 84a0da1..a25f6d5 100644 --- a/include/aclwebserver.h +++ b/include/aclwebserver.h @@ -13,8 +13,6 @@ #include #include - - class ACLWebServerClass{ public: @@ -40,7 +38,7 @@ class ACLWebServerClass{ } } // Create a JSON array to store the users - StaticJsonDocument<512> jsonDoc; + DynamicJsonDocument jsonDoc(ESP.getMaxAllocHeap()); JsonArray usersArray = jsonDoc.to(); // Retrieve the ACL data using the getter function @@ -83,6 +81,19 @@ class ACLWebServerClass{ String cardId = String(request->arg("cardId")); String desc = String(request->arg("desc")); + + if (!cardId.length() > 0 ) { + AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"cardId May not be Empty.\"}"); + request->send(response); + } + + + if (!desc.length() > 0 ) { + AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"desc May not be Empty.\"}"); + request->send(response); + } + + if (acl.validateAccess(String(cardId))) { AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Duplicate ACL\"}"); request->send(response); @@ -120,6 +131,24 @@ class ACLWebServerClass{ String cardId = String(request->arg("cardId")); String newCardId = String(request->arg("newCardId")); String desc = String(request->arg("desc")); + + + + if (!cardId.length() > 0 ) { + AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"cardId May not be Empty.\"}"); + request->send(response); + } + + if (!newCardId.length() > 0 ) { + AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"newCardId May not be Empty.\"}"); + request->send(response); + } + + if (!desc.length() > 0 ) { + AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"desc May not be Empty.\"}"); + request->send(response); + } + acl.updateUser(cardId, newCardId, desc); acl.saveToEEPROM(); request->send(201); // Created @@ -138,6 +167,13 @@ class ACLWebServerClass{ request->send(response); } String cardId = String(request->arg("cardId")); + + + if (!cardId.length() > 0 ) { + AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"cardId May not be Empty.\"}"); + request->send(response); + } + acl.removeUser(cardId); acl.saveToEEPROM(); request->send(201); // Created