dynamic memory
This commit is contained in:
parent
d1b423d6bf
commit
b5623e2a74
1 changed files with 39 additions and 3 deletions
|
@ -13,8 +13,6 @@
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ACLWebServerClass{
|
class ACLWebServerClass{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -40,7 +38,7 @@ class ACLWebServerClass{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create a JSON array to store the users
|
// Create a JSON array to store the users
|
||||||
StaticJsonDocument<512> jsonDoc;
|
DynamicJsonDocument jsonDoc(ESP.getMaxAllocHeap());
|
||||||
JsonArray usersArray = jsonDoc.to<JsonArray>();
|
JsonArray usersArray = jsonDoc.to<JsonArray>();
|
||||||
|
|
||||||
// Retrieve the ACL data using the getter function
|
// Retrieve the ACL data using the getter function
|
||||||
|
@ -83,6 +81,19 @@ class ACLWebServerClass{
|
||||||
String cardId = String(request->arg("cardId"));
|
String cardId = String(request->arg("cardId"));
|
||||||
String desc = String(request->arg("desc"));
|
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))) {
|
if (acl.validateAccess(String(cardId))) {
|
||||||
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Duplicate ACL\"}");
|
AsyncWebServerResponse *response = request->beginResponse(400, "application/json", "{\"msg\":\"Duplicate ACL\"}");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
@ -120,6 +131,24 @@ class ACLWebServerClass{
|
||||||
String cardId = String(request->arg("cardId"));
|
String cardId = String(request->arg("cardId"));
|
||||||
String newCardId = String(request->arg("newCardId"));
|
String newCardId = String(request->arg("newCardId"));
|
||||||
String desc = String(request->arg("desc"));
|
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.updateUser(cardId, newCardId, desc);
|
||||||
acl.saveToEEPROM();
|
acl.saveToEEPROM();
|
||||||
request->send(201); // Created
|
request->send(201); // Created
|
||||||
|
@ -138,6 +167,13 @@ class ACLWebServerClass{
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
String cardId = String(request->arg("cardId"));
|
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.removeUser(cardId);
|
||||||
acl.saveToEEPROM();
|
acl.saveToEEPROM();
|
||||||
request->send(201); // Created
|
request->send(201); // Created
|
||||||
|
|
Loading…
Reference in a new issue