emsApplication/applications/WebConfigure/cgiCommon/handleLoginRequest.cpp

94 lines
1.7 KiB
C++
Raw Normal View History

2024-05-24 12:19:45 +08:00
#include <string>
#include <iostream>
#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
#include "handleHeader.h"
2024-06-05 20:52:33 +08:00
#include "openjson.h"
#include "opmysql.h"
2024-05-24 12:19:45 +08:00
using namespace cgicc;
// <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void handleLoginRequest(cgicc::Cgicc& cgi)
{
2024-06-04 13:36:17 +08:00
#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
2024-05-24 12:19:45 +08:00
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 << "<br/>\n";
fi = cgi.getElement("Password");
if (!fi->isEmpty() && fi != (*cgi).end())
{
passwd = **fi;
std::cout << "Password:" << **fi << std::endl;
}
std::cout << "<br/>\n";
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>߼<EFBFBD>...
2024-06-05 20:52:33 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>в<EFBFBD>ѯ
bool dbok = OpDatabase::getInstance()->OpenDatabase("127.0.0.1", "root");
std::string jsonResult;
if (!dbok)
{
std::cout << "<br/>\n";
std::cout << ("failed to retrieve user info") << std::endl;
}
else
{
if (!OpDatabase::getInstance()->queryUser(username, passwd, jsonResult))
{
std::cout << "<br/>\n";
std::cout << ("invalid user") << std::endl;
}
else
{
std::cout << "<br/>\n";
std::cout << h1("Login Successful!") << std::endl;
}
}
2024-05-24 12:19:45 +08:00
std::cout << "<br/>\n";
2024-06-05 20:52:33 +08:00
std::cout << jsonResult << std::endl;
2024-05-24 12:19:45 +08:00
// Close the document
std::cout << body() << html();
2024-06-05 20:52:33 +08:00
2024-06-04 13:36:17 +08:00
#endif
2024-05-24 12:19:45 +08:00
}