mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
adding dataTypeConverter and JsonGetUserInfos
This commit is contained in:
parent
458c99958f
commit
061122f219
@ -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");
|
||||
|
||||
125
src/cpp/JSONInterface/JsonGetUserInfos.cpp
Normal file
125
src/cpp/JSONInterface/JsonGetUserInfos.cpp
Normal file
@ -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<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("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<Poco::URI::QueryParameters>();
|
||||
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;
|
||||
}
|
||||
16
src/cpp/JSONInterface/JsonGetUserInfos.h
Normal file
16
src/cpp/JSONInterface/JsonGetUserInfos.h
Normal file
@ -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_
|
||||
36
src/cpp/lib/DataTypeConverter.cpp
Normal file
36
src/cpp/lib/DataTypeConverter.cpp
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/cpp/lib/DataTypeConverter.h
Normal file
11
src/cpp/lib/DataTypeConverter.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef __GRADIDO_LOGIN_SERVER_LIB_DATA_TYPE_CONVERTER_H
|
||||
#define __GRADIDO_LOGIN_SERVER_LIB_DATA_TYPE_CONVERTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace DataTypeConverter {
|
||||
|
||||
int strToInt(const std::string& input);
|
||||
};
|
||||
|
||||
#endif // __GRADIDO_LOGIN_SERVER_LIB_DATA_TYPE_CONVERTER_H
|
||||
Loading…
x
Reference in New Issue
Block a user