emsApplication/applications/WebConfigure/cgiCommon/handleLoginRequest.cpp

95 lines
1.7 KiB
C++

#include <string>
#include <iostream>
#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
#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 << "<br/>\n";
fi = cgi.getElement("Password");
if (!fi->isEmpty() && fi != (*cgi).end())
{
passwd = **fi;
std::cout << "Password:" << **fi << std::endl;
}
std::cout << "<br/>\n";
// 处理登录逻辑...
//从数据库中查询
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;
}
}
std::cout << "<br/>\n";
std::cout << jsonResult << std::endl;
// Close the document
std::cout << body() << html();
#endif
}