Archived
79 lines
2.3 KiB
C++
79 lines
2.3 KiB
C++
#include <mysql.hpp>
|
|
#include <database.hpp>
|
|
#include <html5.hpp>
|
|
#include <string>
|
|
#include <cgicc/Cgicc.h>
|
|
#include <iostream>
|
|
|
|
bool login=false;
|
|
bool member=false;
|
|
|
|
int main(){
|
|
mysqlpp::Connection database;
|
|
userdata user;
|
|
cgicc::Cgicc cgi;
|
|
std::string s_id = get_cookie(cgi,"id");
|
|
std::string s_loginkey = get_cookie(cgi,"loginkey");
|
|
if(s_id==""||s_id.find_first_not_of("0123456789")!=std::string::npos||std::stoul(s_id)>UINT64_MAX){
|
|
s_id="";
|
|
}
|
|
if(s_loginkey==""||s_loginkey.find_first_not_of("0123456789")!=std::string::npos||std::stoul(s_loginkey)>UINT64_MAX){
|
|
s_loginkey="";
|
|
}
|
|
if(!connect_mysql(&database)){
|
|
std::cout << "Content-type:text/html\r\n\r\n"
|
|
<< "<html>\n"
|
|
<< "<head>\n"
|
|
<< "<meta charset=\"utf-8\">\n"
|
|
<< "<title>出现错误!</title>\n"
|
|
<< "</head>\n"
|
|
<< "<body>\n"
|
|
<< "数据库连接失败,请检查服务器状态!\n"
|
|
<< "</body>\n"
|
|
<< "</html>\n";
|
|
return 0;
|
|
}
|
|
if(s_id!=""&&query_userdata(database,&user,"id = "+s_id)){
|
|
if(s_loginkey!=""&&user.loginkey==std::stoul(s_loginkey)){
|
|
login=true;
|
|
}
|
|
if(user.status=='m'){
|
|
member=true;
|
|
}
|
|
if(!login&&member){
|
|
member=false;
|
|
}
|
|
if(user.status=='e'){
|
|
login=false;
|
|
}
|
|
}
|
|
if(login){
|
|
std::cout << "Content-type:text/html\r\n\r\n"
|
|
<< "<html>\n"
|
|
<< "<head>\n"
|
|
<< "<meta charset=\"utf-8\">\n"
|
|
<< "<title>安岛百合视频站</title>\n"
|
|
<< "</head>\n"
|
|
<< "<body>\n"
|
|
<< "<h1>欢迎来到安岛百合视频站!</h1>\n"
|
|
<< "欢迎回来," << user.name;
|
|
if(!member){
|
|
std::cout << "(游客)";
|
|
}
|
|
std::cout << "</body>\n"
|
|
<< "</html>\n";
|
|
}else{
|
|
std::cout << "Content-type:text/html\r\n\r\n"
|
|
<< "<html>\n"
|
|
<< "<head>\n"
|
|
<< "<meta charset=\"utf-8\">\n"
|
|
<< "<title>安岛百合视频站</title>\n"
|
|
<< "</head>\n"
|
|
<< "<body>\n"
|
|
<< "<h1>欢迎来到安岛百合视频站!</h1>\n"
|
|
<< "请先登录! <a href=\"/login/\">登录</a> <a href=\"/register/\">注册</a></br>\n"
|
|
<< "</body>\n"
|
|
<< "</html>\n";
|
|
}
|
|
return 0;
|
|
} |