diff --git a/CMakeLists.txt b/CMakeLists.txt index 61f2530ed..9bbdddf3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,10 @@ set(MYSQL_INCLUDE_DIR "dependencies/mariadb-connector-c/include") # "I:/FremdCode/C++/ssl/include" #) +set(CMAKE_CXX_FLAGS "/MP /EHsc") +#set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") +#set(CMAKE_CXX_FLAGS_RELEASE "-O3") + else(WIN32) find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build" REQUIRED) # set vars for mariadb cmake files @@ -110,8 +114,13 @@ include_directories( "build/dependencies/mariadb-connector-c/include" ) + + endif(WIN32) + + + target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519}) if(WIN32) TARGET_LINK_LIBRARIES(Gradido_LoginServer optimized ${MYSQL_LIBRARIES} Shlwapi) @@ -140,6 +149,7 @@ add_executable(Gradido_LoginServer_Test ${LOCAL_SRCS} ${TEST}) target_compile_definitions(Gradido_LoginServer_Test PUBLIC "_TEST_BUILD") target_link_libraries(Gradido_LoginServer_Test ${CONAN_LIBS} ${IROHA_ED25519}) + if(WIN32) TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test optimized ${MYSQL_LIBRARIES} Shlwapi) TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi) diff --git a/src/cpp/HTTPInterface/ElopageWebhook.cpp b/src/cpp/HTTPInterface/ElopageWebhook.cpp index 1c6f15c9b..dd643e6ab 100644 --- a/src/cpp/HTTPInterface/ElopageWebhook.cpp +++ b/src/cpp/HTTPInterface/ElopageWebhook.cpp @@ -34,7 +34,7 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: Poco::Net::NameValueCollection elopageRequestData; int breakCount = 100; while (stream.good() && breakCount > 0) { - char dummy; +// char dummy; char keyBuffer[30]; memset(keyBuffer, 0, 30); char valueBuffer[75]; memset(valueBuffer, 0, 75); /*stream.get(keyBuffer, 30, '=').get(dummy) @@ -195,6 +195,7 @@ int HandleElopageRequestTask::getUserIdFromDB() } catch (Poco::Exception& ex) { addError(new ParamError(__FUNCTION__, "mysql error selecting from db", ex.displayText().data())); + addError(new ParamError(__FUNCTION__, "email: ", mEmail.data())); } return user_id; @@ -378,7 +379,9 @@ int HandleElopageRequestTask::run() addError(param_error_order_id); sendErrorsAsEmail(); } - delete param_error_order_id; + else { + delete param_error_order_id; + } return 0; } \ No newline at end of file diff --git a/src/cpp/SingletonManager/MemoryManager.cpp b/src/cpp/SingletonManager/MemoryManager.cpp index 6781c9c43..c301db15e 100644 --- a/src/cpp/SingletonManager/MemoryManager.cpp +++ b/src/cpp/SingletonManager/MemoryManager.cpp @@ -81,12 +81,13 @@ MemoryManager::MemoryManager() mMemoryPageStacks[1] = new MemoryPageStack(64); // privkey mMemoryPageStacks[2] = new MemoryPageStack(65); // pubkey hex mMemoryPageStacks[3] = new MemoryPageStack(96); // privkey encrypted + mMemoryPageStacks[4] = new MemoryPageStack(161); // privkey hex } MemoryManager::~MemoryManager() { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 5; i++) { delete mMemoryPageStacks[i]; } } @@ -98,6 +99,7 @@ Poco::Int8 MemoryManager::getMemoryStackIndex(Poco::UInt16 size) case 64: return 1; case 65: return 2; case 96: return 3; + case 161: return 4; default: return -1; } return -1; diff --git a/src/cpp/SingletonManager/MemoryManager.h b/src/cpp/SingletonManager/MemoryManager.h index 4145bd7bd..1dca91678 100644 --- a/src/cpp/SingletonManager/MemoryManager.h +++ b/src/cpp/SingletonManager/MemoryManager.h @@ -76,7 +76,7 @@ protected: Poco::Int8 getMemoryStackIndex(Poco::UInt16 size); MemoryManager(); - MemoryPageStack* mMemoryPageStacks[4]; + MemoryPageStack* mMemoryPageStacks[5]; }; diff --git a/src/cpp/controller/EmailVerificationCode.cpp b/src/cpp/controller/EmailVerificationCode.cpp index 7e8ac57cd..b20c79646 100644 --- a/src/cpp/controller/EmailVerificationCode.cpp +++ b/src/cpp/controller/EmailVerificationCode.cpp @@ -27,18 +27,18 @@ namespace controller { // --------------- static members ----------------------------- - Poco::AutoPtr EmailVerificationCode::create(int user_id) + Poco::AutoPtr EmailVerificationCode::create(int user_id, model::table::EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/) { auto code = createEmailVerificationCode(); - auto db = new model::table::EmailOptIn(code, user_id); + auto db = new model::table::EmailOptIn(code, user_id, type); auto result = new EmailVerificationCode(db); return Poco::AutoPtr(result); } - Poco::AutoPtr EmailVerificationCode::create() + Poco::AutoPtr EmailVerificationCode::create(model::table::EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/) { auto code = createEmailVerificationCode(); - auto db = new model::table::EmailOptIn(code); + auto db = new model::table::EmailOptIn(code, type); auto result = new EmailVerificationCode(db); return Poco::AutoPtr(result); } diff --git a/src/cpp/controller/EmailVerificationCode.h b/src/cpp/controller/EmailVerificationCode.h index 20703dfc8..8b94d06bb 100644 --- a/src/cpp/controller/EmailVerificationCode.h +++ b/src/cpp/controller/EmailVerificationCode.h @@ -12,8 +12,8 @@ namespace controller { ~EmailVerificationCode(); - static Poco::AutoPtr create(int user_id); - static Poco::AutoPtr create(); + static Poco::AutoPtr create(int user_id, model::table::EmailOptInType type = model::table::EMAIL_OPT_IN_REGISTER); + static Poco::AutoPtr create(model::table::EmailOptInType type = model::table::EMAIL_OPT_IN_REGISTER); inline Poco::AutoPtr getModel() { return _getModel(); } std::string getLink(); diff --git a/src/cpp/controller/User.h b/src/cpp/controller/User.h index d42757599..1bd3ed62c 100644 --- a/src/cpp/controller/User.h +++ b/src/cpp/controller/User.h @@ -15,8 +15,8 @@ namespace controller { static Poco::AutoPtr create(); static Poco::AutoPtr create(const std::string& email, const std::string& first_name, const std::string& last_name, Poco::UInt64 passwordHashed = 0, std::string languageKey = "de"); - inline int load(const std::string& email) { return getModel()->loadFromDB("email", email); } - inline int load(int user_id) { return getModel()->loadFromDB("id", user_id); } + inline size_t load(const std::string& email) { return getModel()->loadFromDB("email", email); } + inline size_t load(int user_id) { return getModel()->loadFromDB("id", user_id); } int load(const unsigned char* pubkey_array); inline Poco::AutoPtr getModel() { return _getModel(); } diff --git a/src/cpp/model/Email.cpp b/src/cpp/model/Email.cpp index 4779cac1d..15b2a13e5 100644 --- a/src/cpp/model/Email.cpp +++ b/src/cpp/model/Email.cpp @@ -48,6 +48,12 @@ Gradido Login Server\ { } + Email::Email(AutoPtr user, EmailType type) + : mUser(user), mType(type) + { + + } + Email::~Email() { while (mAdditionalStringPartSrcs.size() > 0) { diff --git a/src/cpp/model/Email.h b/src/cpp/model/Email.h index e3be467ac..8fe0e85cc 100644 --- a/src/cpp/model/Email.h +++ b/src/cpp/model/Email.h @@ -35,6 +35,7 @@ namespace model { { public: Email(AutoPtr emailVerification, AutoPtr user, EmailType type); + Email(AutoPtr user, EmailType type); //! \param errors copy errors into own memory Email(const std::string& errorHtml, EmailType type); ~Email(); diff --git a/src/cpp/model/Session.cpp b/src/cpp/model/Session.cpp index a7e18700b..917088ce4 100644 --- a/src/cpp/model/Session.cpp +++ b/src/cpp/model/Session.cpp @@ -9,6 +9,7 @@ #include "../SingletonManager/SessionManager.h" #include "../SingletonManager/ConnectionManager.h" #include "../SingletonManager/ErrorManager.h" +#include "../SingletonManager/EmailManager.h" #include "../tasks/PrepareEmailTask.h" #include "../tasks/SendEmailTask.h" @@ -18,6 +19,8 @@ #include "../controller/User.h" +#include "table/ModelBase.h" + #include "sodium.h" @@ -379,9 +382,27 @@ int Session::updateEmailVerification(Poco::UInt64 emailVerificationCode) return 0; } -bool Session::createNewEmailVerificationCode() + +bool Session::resetPassword(Poco::AutoPtr user, bool passphraseMemorized) { - mEmailVerificationCodeObject = controller::EmailVerificationCode::create(mNewUser->getModel()->getID()); + mNewUser = user; + if (passphraseMemorized) { + mEmailVerificationCodeObject = controller::EmailVerificationCode::create(mNewUser->getModel()->getID(), model::table::EMAIL_OPT_IN_RESET_PASSWORD); + auto emailVerificationModel = mEmailVerificationCodeObject->getModel(); + UniLib::controller::TaskPtr insertEmailVerificationCode( + new model::table::ModelInsertTask(emailVerificationModel, true) + ); + insertEmailVerificationCode->scheduleTask(insertEmailVerificationCode); + UniLib::controller::TaskPtr sendEmail(new SendEmailTask( + new model::Email(mEmailVerificationCodeObject, mNewUser, model::EMAIL_USER_RESET_PASSWORD), + ServerConfig::g_CPUScheduler, 1) + ); + sendEmail->setParentTaskPtrInArray(insertEmailVerificationCode, 0); + sendEmail->scheduleTask(sendEmail); + } + else { + EmailManager::getInstance()->addEmail(new model::Email(user, model::EMAIL_ADMIN_RESET_PASSWORD_REQUEST_WITHOUT_MEMORIZED_PASSPHRASE)); + } return true; } diff --git a/src/cpp/model/Session.h b/src/cpp/model/Session.h index fc576c25e..044270222 100644 --- a/src/cpp/model/Session.h +++ b/src/cpp/model/Session.h @@ -90,7 +90,8 @@ public: //! 0 = ok int updateEmailVerification(Poco::UInt64 emailVerificationCode); - bool createNewEmailVerificationCode(); + // called from page with same name + bool resetPassword(Poco::AutoPtr user, bool passphraseMemorized); Poco::Net::HTTPCookie getLoginCookie(); diff --git a/src/cpp/model/TransactionBase.h b/src/cpp/model/TransactionBase.h index c808dad90..84406fddb 100644 --- a/src/cpp/model/TransactionBase.h +++ b/src/cpp/model/TransactionBase.h @@ -9,6 +9,8 @@ #ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE #define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE +#pragma warning(disable:4800) + #include "../lib/ErrorList.h" #include "../proto/gradido/BasicTypes.pb.h" #include "../SingletonManager/MemoryManager.h" diff --git a/src/cpp/model/TransactionCreation.h b/src/cpp/model/TransactionCreation.h index af489c5c7..6db89f3e7 100644 --- a/src/cpp/model/TransactionCreation.h +++ b/src/cpp/model/TransactionCreation.h @@ -9,6 +9,8 @@ #ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE #define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE +#pragma warning(disable:4800) + #include "TransactionBase.h" #include "../proto/gradido/TransactionCreation.pb.h" #include "User.h" diff --git a/src/cpp/model/TransactionTransfer.h b/src/cpp/model/TransactionTransfer.h index 01b8e2984..dc94e8c5b 100644 --- a/src/cpp/model/TransactionTransfer.h +++ b/src/cpp/model/TransactionTransfer.h @@ -9,6 +9,8 @@ #ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE #define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE +#pragma warning(disable:4800) + #include "TransactionBase.h" #include "../proto/gradido/Transfer.pb.h" diff --git a/src/cpp/model/table/ElopageBuy.cpp b/src/cpp/model/table/ElopageBuy.cpp index c6005a1be..f4b667487 100644 --- a/src/cpp/model/table/ElopageBuy.cpp +++ b/src/cpp/model/table/ElopageBuy.cpp @@ -1,4 +1,5 @@ #include "ElopageBuy.h" +#include "Poco/DateTimeFormatter.h" using namespace Poco::Data::Keywords; @@ -66,6 +67,22 @@ namespace model { return insert; } + + std::string ElopageBuy::toString() + { + std::stringstream ss; + ss << "affiliate program id: " << mIDs[ELOPAGE_BUY_AFFILIATE_PROGRAM_ID] << std::endl; + ss << "publisher id: " << mIDs[ELOPAGE_BUY_PUBLISHER_ID] << std::endl; + ss << "order id: " << mIDs[ELOPAGE_BUY_ORDER_ID] << std::endl; + ss << "product id: " << mIDs[ELOPAGE_BUY_PRODUCT_ID] << std::endl; + ss << "product price: " << mIDs[ELOPAGE_BUY_PRODUCT_PRICE] << std::endl; + ss << "payer email: " << mPayerEmail << std::endl; + ss << "publisher email: " << mPublisherEmail << std::endl; + ss << "payed: " << mPayed << std::endl; + ss << "success date: " << Poco::DateTimeFormatter::format(mSuccessDate, "%d.%m.%Y %H:%M:%S") << std::endl; + ss << "event: " << mEvent << std::endl; + return ss.str(); + } Poco::Data::Statement ElopageBuy::_loadFromDB(Poco::Data::Session session, const std::string& fieldName) { diff --git a/src/cpp/model/table/ElopageBuy.h b/src/cpp/model/table/ElopageBuy.h index cde99c9ca..d7ad1c5a8 100644 --- a/src/cpp/model/table/ElopageBuy.h +++ b/src/cpp/model/table/ElopageBuy.h @@ -36,6 +36,7 @@ namespace model { // generic db operations const char* getTableName() { return "elopage_buys"; } + std::string toString(); protected: Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); diff --git a/src/cpp/model/table/EmailOptIn.cpp b/src/cpp/model/table/EmailOptIn.cpp index 66fbc3ab3..dc5146c1b 100644 --- a/src/cpp/model/table/EmailOptIn.cpp +++ b/src/cpp/model/table/EmailOptIn.cpp @@ -6,14 +6,14 @@ using namespace Poco::Data::Keywords; namespace model { namespace table { - EmailOptIn::EmailOptIn(const Poco::UInt64& code, int user_id) - : mUserId(user_id), mEmailVerificationCode(code) + EmailOptIn::EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/) + : mUserId(user_id), mEmailVerificationCode(code), mType(type) { } - EmailOptIn::EmailOptIn(const Poco::UInt64& code) - : mUserId(0), mEmailVerificationCode(code) + EmailOptIn::EmailOptIn(const Poco::UInt64& code, EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/) + : mUserId(0), mEmailVerificationCode(code), mType(type) { } @@ -36,8 +36,8 @@ namespace model { lock(); insert << "INSERT INTO " << getTableName() - << " (user_id, verification_code) VALUES(?,?)" - , bind(mUserId), bind(mEmailVerificationCode); + << " (user_id, verification_code, email_opt_in_type_id) VALUES(?,?,?))" + , bind(mUserId), bind(mEmailVerificationCode), bind(mType); unlock(); return insert; } @@ -47,12 +47,33 @@ namespace model { { Poco::Data::Statement select(session); - select << "SELECT user_id, verification_code FROM " << getTableName() + int iType = 0; + select << "SELECT user_id, verification_code, email_opt_in_type_id FROM " << getTableName() << " where " << fieldName << " = ?" - , into(mUserId), into(mEmailVerificationCode); + , into(mUserId), into(mEmailVerificationCode), into(iType); + + mType = static_cast(iType); return select; } + + std::string EmailOptIn::toString() + { + std::stringstream ss; + ss << "code: " << mEmailVerificationCode << std::endl; + ss << "user_id: " << mUserId << std::endl; + ss << "type: " << typeToString(mType) << std::endl; + return ss.str(); + } + + const char* EmailOptIn::typeToString(EmailOptInType type) + { + switch (type) { + case EMAIL_OPT_IN_REGISTER: return "register"; + case EMAIL_OPT_IN_RESET_PASSWORD: return "resetPassword"; + default: return ""; + } + } } } diff --git a/src/cpp/model/table/EmailOptIn.h b/src/cpp/model/table/EmailOptIn.h index 73bce2028..578915511 100644 --- a/src/cpp/model/table/EmailOptIn.h +++ b/src/cpp/model/table/EmailOptIn.h @@ -8,19 +8,28 @@ namespace model { namespace table { + + enum EmailOptInType { + EMAIL_OPT_IN_REGISTER = 1, + EMAIL_OPT_IN_RESET_PASSWORD = 2 + }; + class EmailOptIn : public ModelBase { public: - EmailOptIn(const Poco::UInt64& code, int user_id); - EmailOptIn(const Poco::UInt64& code); + EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type); + EmailOptIn(const Poco::UInt64& code, EmailOptInType type); EmailOptIn(); ~EmailOptIn(); // generic db operations const char* getTableName() { return "email_opt_in"; } + std::string toString(); inline Poco::UInt64 getCode() const { return mEmailVerificationCode; } inline void setCode(Poco::UInt64 code) { mEmailVerificationCode = code; } + + static const char* typeToString(EmailOptInType type); protected: Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName); Poco::Data::Statement _insertIntoDB(Poco::Data::Session session); @@ -28,6 +37,8 @@ namespace model { // data type must be a multiple of 4 Poco::UInt64 mEmailVerificationCode; int mUserId; + EmailOptInType mType; + }; } diff --git a/src/cpp/model/table/ModelBase.cpp b/src/cpp/model/table/ModelBase.cpp index 95c6288e8..52c5f31cb 100644 --- a/src/cpp/model/table/ModelBase.cpp +++ b/src/cpp/model/table/ModelBase.cpp @@ -10,8 +10,8 @@ namespace model { namespace table { - ModelInsertTask::ModelInsertTask(Poco::AutoPtr model) - : UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model) + ModelInsertTask::ModelInsertTask(Poco::AutoPtr model, bool emailErrors /* = false */) + : UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mEmailErrors(emailErrors) { #ifdef _UNI_LIB_DEBUG setName(model->getTableName()); @@ -21,8 +21,12 @@ namespace model { int ModelInsertTask::run() { - mModel->insertIntoDB(); - return 0; + auto result = mModel->insertIntoDB(); + if (mModel->errorCount() > 0 && mEmailErrors) { + mModel->sendErrorsAsEmail(); + } + return !result; + //return 0; } // --------------------------------------------------------------------------------------------------- @@ -41,13 +45,16 @@ namespace model { size_t resultCount = 0; try { + return insert.execute() == 1; } catch (Poco::Exception& ex) { lock(); addError(new ParamError(getTableName(), "mysql error by insert", ex.displayText().data())); + addError(new ParamError(getTableName(), "data set: ", toString().data())); unlock(); } + //printf("data valid: %s\n", toString().data()); return false; } diff --git a/src/cpp/model/table/ModelBase.h b/src/cpp/model/table/ModelBase.h index 6794c2fe2..2b9f3067e 100644 --- a/src/cpp/model/table/ModelBase.h +++ b/src/cpp/model/table/ModelBase.h @@ -22,6 +22,7 @@ namespace model { virtual ~ModelBase(); virtual const char* getTableName() = 0; + virtual std::string toString() = 0; template size_t updateIntoDB(const std::string& fieldName, const T& fieldValue ); template size_t loadFromDB(const std::string& fieldName, const T& fieldValue); @@ -100,13 +101,14 @@ namespace model { class ModelInsertTask : public UniLib::controller::CPUTask { public: - ModelInsertTask(Poco::AutoPtr model); + ModelInsertTask(Poco::AutoPtr model, bool emailErrors = false); int run(); const char* getResourceType() const { return "ModelInsertTask"; }; protected: Poco::AutoPtr mModel; + bool mEmailErrors; }; @@ -115,8 +117,8 @@ namespace model { class ModelUpdateTask : public UniLib::controller::CPUTask { public: - ModelUpdateTask(Poco::AutoPtr model, const std::string& fieldName, const T& fieldValue) - : UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mFieldName(fieldName), mFieldValue(fieldValue) + ModelUpdateTask(Poco::AutoPtr model, const std::string& fieldName, const T& fieldValue, bool emailErrors = false) + : UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mFieldName(fieldName), mFieldValue(fieldValue), mEmailErrors(emailErrors) { #ifdef _UNI_LIB_DEBUG setName(model->getTableName()); @@ -124,7 +126,11 @@ namespace model { } int run() { - mModel->updateIntoDB(mFieldName, mFieldValue); + auto result = mModel->updateIntoDB(mFieldName, mFieldValue); + if (mModel->errorCount() > 0 && mEmailErrors) { + mModel->sendErrorsAsEmail(); + } + return !(result > 0); } const char* getResourceType() const { return "ModelUpdateTask"; }; @@ -132,6 +138,7 @@ namespace model { Poco::AutoPtr mModel; std::string mFieldName; T mFieldValue; + bool mEmailErrors; }; diff --git a/src/cpp/model/table/User.cpp b/src/cpp/model/table/User.cpp index 5fa9bb954..396a58765 100644 --- a/src/cpp/model/table/User.cpp +++ b/src/cpp/model/table/User.cpp @@ -2,6 +2,10 @@ #include "Poco/Data/Binding.h" +#include "sodium.h" + +#include "../../SingletonManager/MemoryManager.h" + using namespace Poco::Data::Keywords; namespace model { @@ -65,11 +69,63 @@ namespace model { { Poco::Data::Statement select(session); - int email_checked = 0; + select << "SELECT id, email, first_name, last_name, password, pubkey, privkey, email_checked, language from " << getTableName() << " where " << fieldName << " = ?", - into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mPasswordHashed), into(mPublicKey), into(mPrivateKey), into(email_checked), into(mLanguageKey); + into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mPasswordHashed), into(mPublicKey), into(mPrivateKey), into(mEmailChecked), into(mLanguageKey); + return select; } + + /* + std::string mEmail; + std::string mFirstName; + std::string mLastName; + + Poco::UInt64 mPasswordHashed; + + Poco::Nullable mPublicKey; + Poco::Nullable mPrivateKey; + // created: Mysql DateTime + + bool mEmailChecked; + std::string mLanguageKey; + + char *sodium_bin2hex(char * const hex, const size_t hex_maxlen, + const unsigned char * const bin, const size_t bin_len); + */ + std::string User::toString() + { + auto mm = MemoryManager::getInstance(); + auto pubkeyHex = mm->getFreeMemory(65); + auto privkeyHex = mm->getFreeMemory(161); + //char pubkeyHex[65], privkeyHex[161]; + + //memset(pubkeyHex, 0, 65); + //memset(privkeyHex, 0, 161); + memset(*pubkeyHex, 0, 65); + memset(*privkeyHex, 0, 161); + + std::stringstream ss; + + if (!mPublicKey.isNull()) { + sodium_bin2hex(*pubkeyHex, 65, mPublicKey.value().content().data(), mPublicKey.value().content().size()); + } + if (!mPrivateKey.isNull()) { + sodium_bin2hex(*privkeyHex, 161, mPrivateKey.value().content().data(), mPrivateKey.value().content().size()); + } + + ss << mFirstName << " " << mLastName << " <" << mEmail << ">" << std::endl; + ss << "password hash: " << mPasswordHashed << std::endl; + ss << "public key: " << (char*)*pubkeyHex << std::endl; + ss << "private key: " << (char*)*privkeyHex << std::endl; + ss << "email checked: " << mEmailChecked << std::endl; + ss << "language key: " << mLanguageKey << std::endl; + + mm->releaseMemory(pubkeyHex); + mm->releaseMemory(privkeyHex); + + return ss.str(); + } } } \ No newline at end of file diff --git a/src/cpp/model/table/User.h b/src/cpp/model/table/User.h index 9073d6ffb..017eb9481 100644 --- a/src/cpp/model/table/User.h +++ b/src/cpp/model/table/User.h @@ -31,7 +31,7 @@ namespace model { // generic db operations const char* getTableName() { return "users"; } - + std::string toString(); // default getter unlocked