feature/webserver-improvement #1
1 changed files with 25 additions and 8 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include "ESPAsyncWebServer.h"
|
#include "ESPAsyncWebServer.h"
|
||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
class MainWebServerClass{
|
class MainWebServerClass{
|
||||||
|
|
||||||
|
@ -40,6 +41,11 @@ class MainWebServerClass{
|
||||||
});
|
});
|
||||||
|
|
||||||
_server->onNotFound([&](AsyncWebServerRequest *request){
|
_server->onNotFound([&](AsyncWebServerRequest *request){
|
||||||
|
if(_authRequired){
|
||||||
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
request->send(200, "application/json", "{\"msg\":\"The content you are looking for was not found\"}");
|
request->send(200, "application/json", "{\"msg\":\"The content you are looking for was not found\"}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -86,25 +92,36 @@ class MainWebServerClass{
|
||||||
});
|
});
|
||||||
|
|
||||||
#ifdef RELAY1
|
#ifdef RELAY1
|
||||||
_server->on("/state/relay1", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
_server->on("/state/relay1", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
if(!request->authenticate(http_username, http_password))
|
if(_authRequired){
|
||||||
return request->requestAuthentication();
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"state\":\""+stateDoor()+"\"}");
|
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"state\":\""+stateDoor()+"\"}");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_server->on("/settings/get/DoorDisabled", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
_server->on("/settings/get/DoorDisabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
|
if(_authRequired){
|
||||||
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+String(settings.DoorDisabled())+"\"}");
|
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"value\":\""+String(settings.DoorDisabled())+"\"}");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
_server->on("/settings/set/DoorDisabled", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
_server->on("/settings/set/DoorDisabled", HTTP_GET, [&] (AsyncWebServerRequest *request) {
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
if(!request->authenticate(http_username, http_password))
|
if(_authRequired){
|
||||||
return request->requestAuthentication();
|
if(!request->authenticate(_username.c_str(), _password.c_str())){
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
value = request->getParam("value")->value();
|
value = request->getParam("value")->value();
|
||||||
if (value == "0") {
|
if (value == "0") {
|
||||||
|
|
Loading…
Reference in a new issue