From edd7797da8408801e53bda628cda5e699d02de49 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Fri, 26 Mar 2021 14:12:51 +0100 Subject: [PATCH] add check session state json function and doc --- docu/login_server.api.md | 44 ++++++++++++++- .../JSONInterface/JsonCheckSessionState.cpp | 53 +++++++++++++++++++ .../cpp/JSONInterface/JsonCheckSessionState.h | 16 ++++++ .../JsonRequestHandlerFactory.cpp | 6 ++- 4 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 login_server/src/cpp/JSONInterface/JsonCheckSessionState.cpp create mode 100644 login_server/src/cpp/JSONInterface/JsonCheckSessionState.h diff --git a/docu/login_server.api.md b/docu/login_server.api.md index 6690abc7f..e1eb113b5 100644 --- a/docu/login_server.api.md +++ b/docu/login_server.api.md @@ -209,4 +209,46 @@ return - info can contain additional info strings - user hasn't password: if user hasn't set a password yet (for example if he was registered via elopage) - email already activated: if email was already checked -- session_id: session_id for new session \ No newline at end of file +- session_id: session_id for new session + + +## Check Running Transactions / password encryption +Check if transactions on login-server for user are processed + +GET http://localhost/login_api/getRunningUserTasks?email=max.musterman%40gmail.de + # OR +POST http://localhost/login_api/getRunningUserTasks +```json +{"email":"max.musterman@gmail.de"} +``` + +return +```json +{ + "state":"success", + "runningTasks": { + "password creation": 0, + "sign transaction": 1, + "prepare transaction": 1, + "ready for sign transaction":0 + } +} +``` +return only entrys which > 0 +- password creation: after register or password change, login possible after tasks is finish +- sign transaction: after check transaction in backend, before transaction is in db +- prepare transaction: after sending transaction to login-server, before they can be checked +- ready for sign transaction: transactions ready for signing from user + +## Check Session State +GET http://localhost/login_api/checkSessionState?session_id=-127182 + +return if session is still open +```json +{"state":"success"} +``` +else return +```json +{"state":"not found", "msg": "session not found"} +``` + diff --git a/login_server/src/cpp/JSONInterface/JsonCheckSessionState.cpp b/login_server/src/cpp/JSONInterface/JsonCheckSessionState.cpp new file mode 100644 index 000000000..d40d27658 --- /dev/null +++ b/login_server/src/cpp/JSONInterface/JsonCheckSessionState.cpp @@ -0,0 +1,53 @@ +#include "JsonCheckSessionState.h" +#include "Poco/URI.h" +#include "../lib/DataTypeConverter.h" +#include "../SingletonManager/SessionManager.h" + +Poco::JSON::Object* JsonCheckSessionState::handle(Poco::Dynamic::Var params) +{ + int session_id = 0; + + bool parameterReaded = false; + // if is json object + if (params.type() == typeid(Poco::JSON::Object::Ptr)) { + Poco::JSON::Object::Ptr paramJsonObject = params.extract(); + /// 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); + parameterReaded = true; + } + catch (Poco::Exception& ex) { + return stateError("json exception", ex.displayText()); + } + } + else if (params.isVector()) { + const Poco::URI::QueryParameters queryParams = params.extract(); + for (auto it = queryParams.begin(); it != queryParams.end(); it++) { + if (it->first == "session_id") { + DataTypeConverter::strToInt(it->second, session_id); + //session_id = it->second; + break; + } + } + parameterReaded = true; + } + else { + return stateError("format not implemented", std::string(params.type().name())); + } + if (!parameterReaded) { + return stateError("parameter couldn't parsed"); + } + auto sm = SessionManager::getInstance(); + auto session = sm->getSession(session_id); + if (session) { + return stateSuccess(); + } + else { + return customStateError("not found", "session not found"); + } + +} \ No newline at end of file diff --git a/login_server/src/cpp/JSONInterface/JsonCheckSessionState.h b/login_server/src/cpp/JSONInterface/JsonCheckSessionState.h new file mode 100644 index 000000000..1b97d849f --- /dev/null +++ b/login_server/src/cpp/JSONInterface/JsonCheckSessionState.h @@ -0,0 +1,16 @@ +#ifndef __JSON_INTERFACE_JSON_CHECK_SESSION_STATE_ +#define __JSON_INTERFACE_JSON_CHECK_SESSION_STATE_ + +#include "JsonRequestHandler.h" + +class JsonCheckSessionState : public JsonRequestHandler +{ +public: + Poco::JSON::Object* handle(Poco::Dynamic::Var params); + +protected: + + +}; + +#endif // __JSON_INTERFACE_JSON_CHECK_SESSION_STATE_ \ No newline at end of file diff --git a/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp b/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp index 5db715db3..903ccfdfb 100644 --- a/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp +++ b/login_server/src/cpp/JSONInterface/JsonRequestHandlerFactory.cpp @@ -4,6 +4,8 @@ #include "../SingletonManager/SessionManager.h" +#include "JsonAdminEmailVerificationResend.h" +#include "JsonCheckSessionState.h" #include "JsonCreateUser.h" #include "JsonGetLogin.h" #include "JsonUnknown.h" @@ -11,7 +13,6 @@ #include "JsonGetRunningUserTasks.h" #include "JsonGetUsers.h" #include "JsonLoginViaEmailVerificationCode.h" -#include "JsonAdminEmailVerificationResend.h" #include "JsonGetUserInfos.h" #include "JsonUpdateUserInfos.h" #include "JsonUnsecureLogin.h" @@ -44,6 +45,9 @@ Poco::Net::HTTPRequestHandler* JsonRequestHandlerFactory::createRequestHandler(c if (url_first_part == "/login") { return new JsonGetLogin; } + else if (url_first_part == "/checkSessionState") { + return new JsonCheckSessionState; + } else if (url_first_part == "/checkTransaction") { return new JsonTransaction; }