diff --git a/src/cpp/JSONInterface/JsonAdminEmailVerificationResend.cpp b/src/cpp/JSONInterface/JsonAdminEmailVerificationResend.cpp index 5e139e088..a4aac6ad1 100644 --- a/src/cpp/JSONInterface/JsonAdminEmailVerificationResend.cpp +++ b/src/cpp/JSONInterface/JsonAdminEmailVerificationResend.cpp @@ -6,6 +6,7 @@ #include "../SingletonManager/EmailManager.h" #include "../controller/User.h" +#include "../controller/EmailVerificationCode.h" Poco::JSON::Object* JsonAdminEmailVerificationResend::handle(Poco::Dynamic::Var params) { @@ -112,8 +113,21 @@ Poco::JSON::Object* JsonAdminEmailVerificationResend::handle(Poco::Dynamic::Var if (userModel->getRole() == model::table::ROLE_ADMIN) { auto receiverUser = controller::User::create(); if (1 == receiverUser->load(email)) { - em->addEmail(new model::Email(receiverUser, model::EMAIL_ADMIN_USER_VERIFICATION_CODE_RESEND)); - result->set("state", "success"); + if (!receiverUser->getModel()->isEmailChecked()) { + auto emailVerification = controller::EmailVerificationCode::create(receiverUser->getModel()->getID(), model::table::EMAIL_OPT_IN_REGISTER); + if (!emailVerification.isNull()) { + em->addEmail(new model::Email(emailVerification, receiverUser, model::EMAIL_ADMIN_USER_VERIFICATION_CODE_RESEND)); + result->set("state", "success"); + } + else { + result->set("state", "error"); + result->set("msg", "no email verification code found"); + } + } + else { + result->set("state", "error"); + result->set("msg", "account already active"); + } } else { result->set("state", "error"); diff --git a/src/cpp/JSONInterface/JsonGetUserInfos.cpp b/src/cpp/JSONInterface/JsonGetUserInfos.cpp new file mode 100644 index 000000000..cf0a16722 --- /dev/null +++ b/src/cpp/JSONInterface/JsonGetUserInfos.cpp @@ -0,0 +1,125 @@ +#include "JsonGetUserInfos.h" + + +Poco::JSON::Object* JsonGetUserInfos::handle(Poco::Dynamic::Var params) +{ + + int session_id = 0; + std::string searchString; + Poco::JSON::Object* result = new Poco::JSON::Object; + // 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("search").convert(searchString); + paramJsonObject->get("session_id").convert(session_id); + } + catch (Poco::Exception& ex) { + printf("[JsonGetUsers::handle] try to use params as jsonObject: %s\n", ex.displayText().data()); + result->set("state", "error"); + result->set("msg", "json exception"); + result->set("details", ex.displayText()); + return result; + } + } + else if (params.isStruct()) { + session_id = params["session_id"]; + searchString = params["search"].toString(); + //std::string miau = params["miau"]; + } + else if (params.isVector()) { + try { + const Poco::URI::QueryParameters queryParams = params.extract(); + for (auto it = queryParams.begin(); it != queryParams.end(); it++) { + if (it->first == "session_id") { + session_id = stoi(it->second); + } + else if (it->first == "search") { + searchString = it->second; + } + } + //auto var = params[0]; + } + catch (const std::invalid_argument& ia) { + result->set("state", "error"); + result->set("msg", "error parsing query params, invalid argument: "); + result->set("details", ia.what()); + return result; + } + catch (const std::out_of_range& oor) { + result->set("state", "error"); + result->set("msg", "error parsing query params, Out of Range error: "); + result->set("details", oor.what()); + return result; + } + catch (const std::logic_error & ler) { + result->set("state", "error"); + result->set("msg", "error parsing query params, Logical error: "); + result->set("details", ler.what()); + return result; + } + catch (Poco::Exception& ex) { + //printf("[JsonGetLogin::handle] exception: %s\n", ex.displayText().data()); + result->set("state", "error"); + result->set("msg", "error parsing query params, Poco Error"); + result->set("details", ex.displayText()); + return result; + } + } + + if (session_id) { + auto sm = SessionManager::getInstance(); + auto session = sm->getSession(session_id); + //Session* session = nullptr; + if (session) { + auto user = session->getNewUser(); + if (user.isNull()) { + result->set("state", "not found"); + result->set("msg", "Session didn't contain user"); + return result; + } + else if (searchString == "") { + result->set("state", "not found"); + result->set("msg", "search string is empty"); + return result; + } + else if (user->getModel()->getRole() != model::table::ROLE_ADMIN) { + result->set("state", "wrong role"); + result->set("msg", "User hasn't correct role"); + return result; + } + + auto results = controller::User::search(searchString); + if (results.size() > 0) { + result->set("state", "success"); + + //Poco::JSON::Object jsonResultObject; + Poco::JSON::Array jsonUsersArray; + + for (auto it = results.begin(); it != results.end(); it++) { + jsonUsersArray.add((*it)->getJson()); + (*it)->release(); + } + results.clear(); + result->set("users", jsonUsersArray); + } + + } + else { + result->set("state", "not found"); + result->set("msg", "session not found"); + } + + } + else { + result->set("state", "error"); + result->set("msg", "empty session id"); + } + + return result; +} \ No newline at end of file diff --git a/src/cpp/JSONInterface/JsonGetUserInfos.h b/src/cpp/JSONInterface/JsonGetUserInfos.h new file mode 100644 index 000000000..fd96f05cf --- /dev/null +++ b/src/cpp/JSONInterface/JsonGetUserInfos.h @@ -0,0 +1,16 @@ +#ifndef __JSON_INTERFACE_JSON_GET_USER_INFOS_ +#define __JSON_INTERFACE_JSON_GET_USER_INFOS_ + +#include "JsonRequestHandler.h" + +class JsonGetUserInfos : public JsonRequestHandler +{ +public: + Poco::JSON::Object* handle(Poco::Dynamic::Var params); + +protected: + + +}; + +#endif // __JSON_INTERFACE_JSON_GET_USER_INFOS_ \ No newline at end of file diff --git a/src/cpp/lib/DataTypeConverter.cpp b/src/cpp/lib/DataTypeConverter.cpp new file mode 100644 index 000000000..a258e4c77 --- /dev/null +++ b/src/cpp/lib/DataTypeConverter.cpp @@ -0,0 +1,36 @@ +#include "DataTypeConverter.h" + +namespace DataTypeConverter +{ + int strToInt(const std::string& input) + { + try { + return stoi(input); + } + catch (const std::invalid_argument& ia) { + result->set("state", "error"); + result->set("msg", "error parsing query params, invalid argument: "); + result->set("details", ia.what()); + return result; + } + catch (const std::out_of_range& oor) { + result->set("state", "error"); + result->set("msg", "error parsing query params, Out of Range error: "); + result->set("details", oor.what()); + return result; + } + catch (const std::logic_error & ler) { + result->set("state", "error"); + result->set("msg", "error parsing query params, Logical error: "); + result->set("details", ler.what()); + return result; + } + catch (Poco::Exception& ex) { + //printf("[JsonGetLogin::handle] exception: %s\n", ex.displayText().data()); + result->set("state", "error"); + result->set("msg", "error parsing query params, Poco Error"); + result->set("details", ex.displayText()); + return result; + } + } +} \ No newline at end of file diff --git a/src/cpp/lib/DataTypeConverter.h b/src/cpp/lib/DataTypeConverter.h new file mode 100644 index 000000000..b568a4096 --- /dev/null +++ b/src/cpp/lib/DataTypeConverter.h @@ -0,0 +1,11 @@ +#ifndef __GRADIDO_LOGIN_SERVER_LIB_DATA_TYPE_CONVERTER_H +#define __GRADIDO_LOGIN_SERVER_LIB_DATA_TYPE_CONVERTER_H + +#include + +namespace DataTypeConverter { + + int strToInt(const std::string& input); +}; + +#endif // __GRADIDO_LOGIN_SERVER_LIB_DATA_TYPE_CONVERTER_H