52 lines
979 B
C++
52 lines
979 B
C++
|
#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;
|
||
|
}
|
||
|
|
||
|
int ret;
|
||
|
if((ret=se.setUser(""))<0)
|
||
|
{
|
||
|
jsonfail(err_session,make_str("Failed to logout. Session Module returns ",ret));
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
j["success"]=1;
|
||
|
}while(0);
|
||
|
|
||
|
res.content.append(j.dump());
|
||
|
res.show();
|
||
|
return 0;
|
||
|
}
|