This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
DBHomework/old_src/logout.cpp
2017-12-28 18:18:44 +08:00

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;
}