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/logout.cpp

52 lines
979 B
C++
Raw Normal View History

2017-11-20 11:43:49 +08:00
#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;
}