#include #include #include #include #include #include #include "handleHeader.h" #include "openjson.h" #include "opmysql.h" using namespace cgicc; // 登录请求处理函数 void handleLoginRequest(cgicc::Cgicc& cgi) { #if 0 handleHtmlHeader(); std::cout << std::endl; // Start the HTML body std::cout << body() << std::endl; std::cout << h1("Login Successful!") << std::endl; // Close the document std::cout << body() << html(); #endif #if 1 handleHtmlHeader(); // Start the HTML body std::cout << body() << std::endl; std::string username; std::string passwd; // Get username and password from form parameters cgicc::form_iterator fi = cgi.getElement("Username"); if (!fi->isEmpty() && fi != (*cgi).end()) { username = **fi; std::cout << "Username:" << **fi << std::endl; } std::cout << "
\n"; fi = cgi.getElement("Password"); if (!fi->isEmpty() && fi != (*cgi).end()) { passwd = **fi; std::cout << "Password:" << **fi << std::endl; } std::cout << "
\n"; // 处理登录逻辑... //从数据库中查询 bool dbok = OpDatabase::getInstance()->OpenDatabase("127.0.0.1", "root"); std::string jsonResult; if (!dbok) { std::cout << "
\n"; std::cout << ("failed to retrieve user info") << std::endl; } else { if (!OpDatabase::getInstance()->queryUser(username, passwd, jsonResult)) { std::cout << "
\n"; std::cout << ("invalid user") << std::endl; } else { std::cout << "
\n"; std::cout << h1("Login Successful!") << std::endl; } } std::cout << "
\n"; std::cout << jsonResult << std::endl; // Close the document std::cout << body() << html(); #endif }