Have a rest!

This commit is contained in:
Kirigaya Kazuto 2017-11-20 14:46:51 +08:00
parent bb4c4dfb0e
commit 0970957b1b
5 changed files with 203 additions and 51 deletions

View File

@ -51,11 +51,14 @@
<Unit filename="HTTPWrapper/Singleton.hpp" /> <Unit filename="HTTPWrapper/Singleton.hpp" />
<Unit filename="HTTPWrapper/Util.cpp" /> <Unit filename="HTTPWrapper/Util.cpp" />
<Unit filename="HTTPWrapper/Util.h" /> <Unit filename="HTTPWrapper/Util.h" />
<Unit filename="MySQLTransaction.cpp" />
<Unit filename="MySQLTransaction.h" />
<Unit filename="MySQLWrapper/MySQLInclude.h" /> <Unit filename="MySQLWrapper/MySQLInclude.h" />
<Unit filename="MySQLWrapper/MySQLWrapper.cpp" /> <Unit filename="MySQLWrapper/MySQLWrapper.cpp" />
<Unit filename="MySQLWrapper/MySQLWrapper.h" /> <Unit filename="MySQLWrapper/MySQLWrapper.h" />
<Unit filename="addbooktype.cpp" />
<Unit filename="json.hpp" /> <Unit filename="json.hpp" />
<Unit filename="jsonfail.cpp" />
<Unit filename="jsonfail.h" />
<Unit filename="mysql_include/big_endian.h" /> <Unit filename="mysql_include/big_endian.h" />
<Unit filename="mysql_include/binary_log_types.h" /> <Unit filename="mysql_include/binary_log_types.h" />
<Unit filename="mysql_include/byte_order_generic.h" /> <Unit filename="mysql_include/byte_order_generic.h" />
@ -120,6 +123,7 @@
<Unit filename="mysql_include/thr_mutex.h" /> <Unit filename="mysql_include/thr_mutex.h" />
<Unit filename="mysql_include/thr_rwlock.h" /> <Unit filename="mysql_include/thr_rwlock.h" />
<Unit filename="mysql_include/typelib.h" /> <Unit filename="mysql_include/typelib.h" />
<Unit filename="removebook.cpp" />
<Extensions> <Extensions>
<code_completion /> <code_completion />
<envvars /> <envvars />

View File

@ -108,21 +108,22 @@
<map> <map>
"Session.h" "Session.h"
1510973094 source:d:\codeblocks_codes\dbhomework\httpwrapper\response.cpp 1511136347 source:d:\codeblocks_codes\dbhomework\httpwrapper\response.cpp
"Response.h" "Response.h"
<sstream> <sstream>
<iostream> <iostream>
1510899277 d:\codeblocks_codes\dbhomework\httpwrapper\response.h 1511136341 d:\codeblocks_codes\dbhomework\httpwrapper\response.h
<string> <string>
"CookieVec.h" "CookieVec.h"
1510902815 source:d:\codeblocks_codes\dbhomework\httpwrapper\util.cpp 1511153903 source:d:\codeblocks_codes\dbhomework\httpwrapper\util.cpp
"Util.h" "Util.h"
<fstream> <fstream>
<sstream> <sstream>
<cstdio>
1510972177 d:\codeblocks_codes\dbhomework\httpwrapper\util.h 1511153929 d:\codeblocks_codes\dbhomework\httpwrapper\util.h
<string> <string>
<sstream> <sstream>
"MySQLWrapper.h" "MySQLWrapper.h"
@ -191,7 +192,7 @@
1510881771 source:d:\codeblocks_codes\dbhomework\httpwrapper\sessionmanager.cpp 1510881771 source:d:\codeblocks_codes\dbhomework\httpwrapper\sessionmanager.cpp
"SessionManager.h" "SessionManager.h"
1511102541 source:d:\codeblocks_codes\dbhomework\httpwrapper\session.cpp 1511147560 source:d:\codeblocks_codes\dbhomework\httpwrapper\session.cpp
"Session.h" "Session.h"
"Singleton.hpp" "Singleton.hpp"
"Util.h" "Util.h"
@ -200,7 +201,7 @@
<cstdlib> <cstdlib>
<cstring> <cstring>
1511102538 d:\codeblocks_codes\dbhomework\httpwrapper\session.h 1511147480 d:\codeblocks_codes\dbhomework\httpwrapper\session.h
"Request.h" "Request.h"
"Response.h" "Response.h"
<string> <string>
@ -218,14 +219,43 @@
"Util.h" "Util.h"
"json.hpp" "json.hpp"
1511074252 source:d:\codeblocks_codes\dbhomework\login.cpp 1511149331 source:d:\codeblocks_codes\dbhomework\login.cpp
"Request.h" "Session.h"
"Response.h"
"Util.h" "Util.h"
"json.hpp" "json.hpp"
"jsonfail.h"
1511102500 source:d:\codeblocks_codes\dbhomework\addbooktype.cpp 1511136779 source:d:\codeblocks_codes\dbhomework\addbooktype.cpp
"Session.h" "Session.h"
"Util.h" "Util.h"
"json.hpp" "json.hpp"
1511149002 source:d:\codeblocks_codes\dbhomework\jsonfail.cpp
"jsonfail.h"
1511153994 d:\codeblocks_codes\dbhomework\jsonfail.h
1511140034 source:d:\codeblocks_codes\dbhomework\editbooktype.cpp
"Session.h"
"Util.h"
"json.hpp"
"jsonfail.h"
1511147914 source:d:\codeblocks_codes\dbhomework\logout.cpp
"Session.h"
"Util.h"
"json.hpp"
"jsonfail.h"
1511155324 source:d:\codeblocks_codes\dbhomework\editbook.cpp
"Session.h"
"Util.h"
"json.hpp"
"jsonfail.h"
1511156714 source:d:\codeblocks_codes\dbhomework\mysqltransaction.cpp
"MySQLTransaction.h"
1511156696 d:\codeblocks_codes\dbhomework\mysqltransaction.h
"MySQLWrapper.h"

View File

@ -2,24 +2,29 @@
<CodeBlocks_layout_file> <CodeBlocks_layout_file>
<FileVersion major="1" minor="0" /> <FileVersion major="1" minor="0" />
<ActiveTarget name="Release" /> <ActiveTarget name="Release" />
<File name="HTTPWrapper\Request.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HTTPWrapper\Response.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="159" topLine="0" /> <Cursor1 position="214" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="HTTPWrapper\Singleton.hpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HTTPWrapper\Util.cpp" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="21" topLine="27" /> <Cursor1 position="102" topLine="3" />
</Cursor> </Cursor>
</File> </File>
<File name="HTTPWrapper\Util.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0"> <File name="HTTPWrapper\Util.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="867" topLine="12" /> <Cursor1 position="158" topLine="30" />
</Cursor> </Cursor>
</File> </File>
<File name="HTTPWrapper\Response.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="removebook.cpp" open="1" top="1" tabpos="17" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="76" topLine="0" /> <Cursor1 position="2103" topLine="63" />
</Cursor>
</File>
<File name="MySQLTransaction.cpp" open="1" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="726" topLine="31" />
</Cursor> </Cursor>
</File> </File>
<File name="MySQLWrapper\MySQLInclude.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="MySQLWrapper\MySQLInclude.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -27,44 +32,19 @@
<Cursor1 position="66" topLine="0" /> <Cursor1 position="66" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="MySQLWrapper\MySQLWrapper.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="MySQLWrapper\MySQLWrapper.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="562" topLine="20" />
</Cursor>
</File>
<File name="addbooktype.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
<Cursor>
<Cursor1 position="983" topLine="32" />
</Cursor>
</File>
<File name="HTTPWrapper\Request.cpp" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3128" topLine="92" />
</Cursor>
</File>
<File name="HTTPWrapper\Response.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="560" topLine="30" />
</Cursor>
</File>
<File name="HTTPWrapper\Session.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="579" topLine="7" />
</Cursor>
</File>
<File name="MySQLWrapper\MySQLWrapper.cpp" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="2643" topLine="96" /> <Cursor1 position="2643" topLine="96" />
</Cursor> </Cursor>
</File> </File>
<File name="HTTPWrapper\Util.cpp" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="MySQLWrapper\MySQLWrapper.h" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="3294" topLine="132" /> <Cursor1 position="655" topLine="26" />
</Cursor> </Cursor>
</File> </File>
<File name="HTTPWrapper\Session.cpp" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HTTPWrapper\CookieVec.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="2514" topLine="117" /> <Cursor1 position="2013" topLine="10" />
</Cursor> </Cursor>
</File> </File>
<File name="HTTPWrapper\CookieVec.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HTTPWrapper\CookieVec.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -72,9 +52,49 @@
<Cursor1 position="960" topLine="0" /> <Cursor1 position="960" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="HTTPWrapper\CookieVec.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="MySQLTransaction.h" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="2013" topLine="10" /> <Cursor1 position="137" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Request.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="159" topLine="0" />
</Cursor>
</File>
<File name="jsonfail.cpp" open="1" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="592" topLine="7" />
</Cursor>
</File>
<File name="HTTPWrapper\Request.cpp" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3128" topLine="47" />
</Cursor>
</File>
<File name="HTTPWrapper\Response.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="294" topLine="3" />
</Cursor>
</File>
<File name="jsonfail.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="251" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Session.cpp" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2516" topLine="162" />
</Cursor>
</File>
<File name="HTTPWrapper\Session.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="541" topLine="0" />
</Cursor>
</File>
<File name="HTTPWrapper\Singleton.hpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="21" topLine="27" />
</Cursor> </Cursor>
</File> </File>
</CodeBlocks_layout_file> </CodeBlocks_layout_file>

@ -1 +1 @@
Subproject commit d4ce5626c4b6eb6e36b59c0811733c8ddf4001ae Subproject commit 2edf907573f06a5d7ce94aa9496c4027db6ac4a6

View File

@ -0,0 +1,98 @@
#include "Session.h"
#include "Util.h"
#include "json.hpp"
#include "jsonfail.h"
using namespace std;
using json=nlohmann::json;
#define postval(NAME) string NAME=req.post[#NAME]
int main()
{
Request req;
Session se(req);
Response res;
json j;
auto jsonfail=[&](int errcode,const string& detail="")
{
j["success"]=0;
j["errcode"]=errcode;
j["errmsg"]=string(GetErrMsg(errcode))+" : "+detail;
};
do
{
if(!se.isReady())
{
jsonfail(err_session);
break;
}
if(se.isNew()||se.getUser().empty())
{
jsonfail(err_need_login);
break;
}
if(req.requestMethod!="POST")
{
jsonfail(err_method_not_supported);
break;
}
if(req.post["book_key"].empty())
{
jsonfail(err_missing_parameter);
break;
}
/// Connect to DB
DBInfo db;
MySQLConn conn;
if(db.readConfig()<0)
{
jsonfail(err_config);
break;
}
if(db.connectProxy(conn)<0)
{
jsonfail(err_connect);
break;
}
/// Check Permission
int permission_level;
if(conn.exec(make_str("select permission_level from bs_user where username='",
se.getUser(),
"'"),
[&](MySQLResult& res)
{
res.stepRow([&](char** val,unsigned long* len)
{
permission_level=ParseInt(val[0]);
});
})<0)
{
jsonfail(err_sql,"Step 1");
break;
}
if(permission_level>1)
{
/// Permission Denied.
jsonfail(err_permission_denied);
break;
}
/// TODO:
}while(0);
res.content.append(j.dump());
res.show();
return 0;
}