mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add logout via json request
This commit is contained in:
parent
6aad6070a4
commit
339150ded6
44
src/cpp/JSONInterface/JsonLogout.cpp
Normal file
44
src/cpp/JSONInterface/JsonLogout.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "JsonLogout.h"
|
||||
|
||||
|
||||
|
||||
#include "../SingletonManager/SessionManager.h"
|
||||
|
||||
|
||||
Poco::JSON::Object* JsonLogout::handle(Poco::Dynamic::Var params)
|
||||
{
|
||||
|
||||
auto sm = SessionManager::getInstance();
|
||||
int session_id = 0;
|
||||
|
||||
// if is json object
|
||||
if (params.type() == typeid(Poco::JSON::Object::Ptr)) {
|
||||
Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>();
|
||||
/// Throws a RangeException if the value does not fit
|
||||
/// into the result variable.
|
||||
/// Throws a NotImplementedException if conversion is
|
||||
/// not available for the given type.
|
||||
/// Throws InvalidAccessException if Var is empty.
|
||||
try {
|
||||
paramJsonObject->get("session_id").convert(session_id);
|
||||
}
|
||||
catch (Poco::Exception& ex) {
|
||||
return stateError("json exception", ex.displayText());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return stateError("parameter format unknown");
|
||||
}
|
||||
|
||||
auto session = sm->getSession(session_id);
|
||||
if (!session) {
|
||||
return stateError("session not found", std::to_string(session_id));
|
||||
}
|
||||
if (sm->releaseSession(session_id)) {
|
||||
return stateSuccess();
|
||||
}
|
||||
return stateError("error by releasing session");
|
||||
|
||||
|
||||
|
||||
}
|
||||
18
src/cpp/JSONInterface/JsonLogout.h
Normal file
18
src/cpp/JSONInterface/JsonLogout.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef __JSON_INTERFACE_JSON_LOGOUT_
|
||||
#define __JSON_INTERFACE_JSON_LOGOUT_
|
||||
|
||||
#include "JsonRequestHandler.h"
|
||||
|
||||
class JsonLogout : public JsonRequestHandler
|
||||
{
|
||||
public:
|
||||
JsonLogout(Poco::Net::IPAddress ip) : mClientIP(ip) {}
|
||||
Poco::JSON::Object* handle(Poco::Dynamic::Var params);
|
||||
|
||||
protected:
|
||||
Poco::Net::IPAddress mClientIP;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // __JSON_INTERFACE_JSON_LOGOUT_
|
||||
@ -1,65 +1,74 @@
|
||||
#include "JsonRequestHandlerFactory.h"
|
||||
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
|
||||
#include "../SingletonManager/SessionManager.h"
|
||||
|
||||
#include "JsonCreateUser.h"
|
||||
#include "JsonGetLogin.h"
|
||||
#include "JsonUnknown.h"
|
||||
#include "JsonTransaction.h"
|
||||
#include "JsonGetRunningUserTasks.h"
|
||||
#include "JsonGetUsers.h"
|
||||
#include "JsonAdminEmailVerificationResend.h"
|
||||
#include "JsonGetUserInfos.h"
|
||||
#include "JsonUpdateUserInfos.h"
|
||||
#include "JsonUnsecureLogin.h"
|
||||
|
||||
JsonRequestHandlerFactory::JsonRequestHandlerFactory()
|
||||
: mRemoveGETParameters("^/([a-zA-Z0-9_-]*)"), mLogging(Poco::Logger::get("requestLog"))
|
||||
{
|
||||
}
|
||||
|
||||
Poco::Net::HTTPRequestHandler* JsonRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest& request)
|
||||
{
|
||||
std::string uri = request.getURI();
|
||||
std::string url_first_part;
|
||||
std::stringstream logStream;
|
||||
|
||||
mRemoveGETParameters.extract(uri, url_first_part);
|
||||
|
||||
std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S");
|
||||
logStream << dateTimeString << " call " << uri;
|
||||
|
||||
mLogging.information(logStream.str());
|
||||
|
||||
if (url_first_part == "/login") {
|
||||
return new JsonGetLogin;
|
||||
}
|
||||
else if (url_first_part == "/checkTransaction") {
|
||||
return new JsonTransaction;
|
||||
}
|
||||
else if (url_first_part == "/getRunningUserTasks") {
|
||||
return new JsonGetRunningUserTasks;
|
||||
}
|
||||
else if (url_first_part == "/getUsers") {
|
||||
return new JsonGetUsers;
|
||||
}
|
||||
else if (url_first_part == "/createUser") {
|
||||
return new JsonCreateUser(request.clientAddress().host());
|
||||
}
|
||||
else if (url_first_part == "/adminEmailVerificationResend") {
|
||||
return new JsonAdminEmailVerificationResend;
|
||||
}
|
||||
else if (url_first_part == "/getUserInfos") {
|
||||
return new JsonGetUserInfos;
|
||||
}
|
||||
else if (url_first_part == "/updateUserInfos") {
|
||||
return new JsonUpdateUserInfos;
|
||||
}
|
||||
else if (url_first_part == "/unsecureLogin" && (ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
|
||||
return new JsonUnsecureLogin(request.clientAddress().host());
|
||||
}
|
||||
|
||||
return new JsonUnknown;
|
||||
}
|
||||
#include "JsonRequestHandlerFactory.h"
|
||||
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
|
||||
#include "../SingletonManager/SessionManager.h"
|
||||
|
||||
#include "JsonCreateUser.h"
|
||||
#include "JsonGetLogin.h"
|
||||
#include "JsonUnknown.h"
|
||||
#include "JsonTransaction.h"
|
||||
#include "JsonGetRunningUserTasks.h"
|
||||
#include "JsonGetUsers.h"
|
||||
#include "JsonAdminEmailVerificationResend.h"
|
||||
#include "JsonGetUserInfos.h"
|
||||
#include "JsonUpdateUserInfos.h"
|
||||
#include "JsonUnsecureLogin.h"
|
||||
#include "JsonLogout.h"
|
||||
|
||||
JsonRequestHandlerFactory::JsonRequestHandlerFactory()
|
||||
: mRemoveGETParameters("^/([a-zA-Z0-9_-]*)"), mLogging(Poco::Logger::get("requestLog"))
|
||||
{
|
||||
}
|
||||
|
||||
Poco::Net::HTTPRequestHandler* JsonRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest& request)
|
||||
{
|
||||
std::string uri = request.getURI();
|
||||
std::string url_first_part;
|
||||
std::stringstream logStream;
|
||||
|
||||
mRemoveGETParameters.extract(uri, url_first_part);
|
||||
|
||||
std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S");
|
||||
logStream << dateTimeString << " call " << uri;
|
||||
|
||||
mLogging.information(logStream.str());
|
||||
|
||||
auto client_host = request.clientAddress().host();
|
||||
//auto client_ip = request.clientAddress();
|
||||
// X-Real-IP forwarded ip from nginx config
|
||||
auto client_host_string = request.get("X-Real-IP", client_host.toString());
|
||||
client_host = Poco::Net::IPAddress(client_host_string);
|
||||
|
||||
if (url_first_part == "/login") {
|
||||
return new JsonGetLogin;
|
||||
}
|
||||
else if (url_first_part == "/checkTransaction") {
|
||||
return new JsonTransaction;
|
||||
}
|
||||
else if (url_first_part == "/getRunningUserTasks") {
|
||||
return new JsonGetRunningUserTasks;
|
||||
}
|
||||
else if (url_first_part == "/getUsers") {
|
||||
return new JsonGetUsers;
|
||||
}
|
||||
else if (url_first_part == "/createUser") {
|
||||
return new JsonCreateUser(client_host);
|
||||
}
|
||||
else if (url_first_part == "/adminEmailVerificationResend") {
|
||||
return new JsonAdminEmailVerificationResend;
|
||||
}
|
||||
else if (url_first_part == "/getUserInfos") {
|
||||
return new JsonGetUserInfos;
|
||||
}
|
||||
else if (url_first_part == "/updateUserInfos") {
|
||||
return new JsonUpdateUserInfos;
|
||||
}
|
||||
else if (url_first_part == "/unsecureLogin" && (ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
|
||||
return new JsonUnsecureLogin(request.clientAddress().host());
|
||||
}
|
||||
else if (url_first_part == "/logout") {
|
||||
return new JsonLogout(client_host);
|
||||
}
|
||||
return new JsonUnknown;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user