20 #include "../../../include/esp3d_config.h"
21 #if defined (HTTP_FEATURE)
22 #include "../http_server.h"
23 #if defined (ARDUINO_ARCH_ESP32)
24 #include <WebServer.h>
25 #endif //ARDUINO_ARCH_ESP32
26 #if defined (ARDUINO_ARCH_ESP8266)
27 #include <ESP8266WebServer.h>
28 #endif //ARDUINO_ARCH_ESP8266
29 #include "../../authentication/authentication_service.h"
30 #include "../../../core/esp3doutput.h"
31 #include "../../../core/settings_esp3d.h"
34 void HTTP_Server::handle_login()
36 #ifdef AUTHENTICATION_FEATURE
38 String status =
"Wrong authentication!";
40 if (_webserver->hasArg(
"DISCONNECT")) {
41 AuthenticationService::ClearCurrentSession();
42 _webserver->sendHeader(
"Set-Cookie",
"ESPSESSIONID=0");
43 _webserver->sendHeader(
"Cache-Control",
"no-cache");
44 _webserver->send(200,
"application/json",
"{\"status\":\"ok\",\"authentication_lvl\":\"guest\"}");
49 if (_webserver->hasArg(
"SUBMIT")) {
51 if (_webserver->hasArg(
"PASSWORD") && _webserver->hasArg(
"USER")) {
53 String sUser = _webserver->arg(
"USER");
55 String sPassword = _webserver->arg(
"PASSWORD");
56 if((((sUser ==
DEFAULT_ADMIN_LOGIN) && (AuthenticationService::isadmin(sPassword.c_str()))) ||
57 ((sUser ==
DEFAULT_USER_LOGIN) && (AuthenticationService::isuser(sPassword.c_str()))))) {
59 if (_webserver->hasArg(
"NEWPASSWORD")) {
60 String newpassword = _webserver->arg(
"NEWPASSWORD");
65 status =
"Set failed!";
72 status =
"Incorrect password!";
76 if (_webserver->hasArg(
"TIMEOUT")) {
77 String timeout = _webserver->arg(
"TIMEOUT");
78 AuthenticationService::setSessionTimeout(timeout.toInt());
86 String session = AuthenticationService::create_session_ID();
88 AuthenticationService::ClearCurrentSession();
91 String tmps =
"ESPSESSIONID=";
93 _webserver->sendHeader(
"Set-Cookie",tmps);
100 _webserver->sendHeader(
"Cache-Control",
"no-cache");
101 String smsg =
"{\"status\":\"";
103 smsg+=
"\",\"authentication_lvl\":\"";
112 _webserver->send(code,
"application/json", smsg);
113 #else // No AUTHENTICATION_FEATURE
114 _webserver->sendHeader(
"Cache-Control",
"no-cache");
115 _webserver->send(200,
"application/json",
"{\"status\":\"ok\",\"authentication_lvl\":\"admin\"}");
116 #endif //AUTHENTICATION_FEATURE
119 #endif //HTTP_FEATURE