/* commands are functions that get called by the webserver framework
 * they can read any posted data from client, and they output to the
 * server to send data back to the web browser. */
void helloCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{

    /* this line sends the standard "we're all OK" headers back to the
     browser */
    server.httpSuccess();
    
    /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
    if (type != WebServer::HEAD)
    {
        /* this defines some HTML text in read-only memory aka PROGMEM.
         * This is needed to avoid having the string copied to our limited
         * amount of RAM. */
        const char *helloMsg = "<html><body><h1>Hello, Costanza!</h1></body></html>";

        /* this is a special form of print that outputs from PROGMEM */
        server.print(helloMsg);
    }
}
void WebManager::getStateCmd(WebServer& server, WebServer::ConnectionType type, char* url_tail, bool tail_complete) {
#ifdef PRINT_DEBUG_MSGS
	Serial.println("ajax_refresh");
#endif
	if (getInstance()->m_webserver->checkCredentials(IOManager::getInstance()->m_credentialsFile->m_authCredentials)) {
		/* for a GET or HEAD, send the standard "it's all OK headers" */
		server.httpSuccess();
		server.print("{'state': ");
		server.print(DoorStateManager::getInstance()->m_currentState->getId());
		server.print(", 'obstacle': ");
		server.print(DoorStateManager::getInstance()->isObstacleDetected() ? "true" : "false");
		server.print(", 'forgottenOpened': ");
		server.print(DoorStateManager::getInstance()->isForgottenOpenedDoor() ? "true" : "false");
		server.print('}');
	} else {
		/* send a 401 error back causing the web browser to prompt the user for credentials */
		server.httpUnauthorized();
	}
}