From f890cac00d0b3bae14570946d39b23d763ce82af Mon Sep 17 00:00:00 2001 From: Dario Date: Mon, 30 Dec 2019 13:12:23 +0100 Subject: [PATCH] update model structure --- CMakeLists.txt | 4 +- src/cpp/HTTPInterface/CheckEmailPage.cpp | 61 ++++++---- src/cpp/HTTPInterface/ElopageWebhook.cpp | 15 +-- .../PageRequestHandlerFactory.cpp | 6 + .../HTTPInterface/UpdateUserPasswordPage.cpp | 3 +- src/cpp/main.cpp | 2 +- src/cpp/model/ElopageBuy.cpp | 77 ------------- src/cpp/model/ElopageBuy.h | 52 --------- src/cpp/model/EmailVerificationCode.cpp | 109 ++++++------------ src/cpp/model/EmailVerificationCode.h | 39 +++---- src/cpp/model/ModelBase.cpp | 93 --------------- src/cpp/model/ModelBase.h | 54 --------- src/cpp/model/Session.cpp | 21 ++++ src/cpp/model/Session.h | 2 + src/cpp/model/TableControllerBase.cpp | 44 +++++++ src/cpp/model/TableControllerBase.h | 45 ++++++++ src/cpp/model/User.h | 3 +- src/cpp/model/table/ElopageBuy.cpp | 82 +++++++++++++ src/cpp/model/table/ElopageBuy.h | 57 +++++++++ src/cpp/model/table/EmailOptIn.cpp | 58 ++++++++++ src/cpp/model/table/EmailOptIn.h | 38 ++++++ src/cpp/model/table/ModelBase.cpp | 106 +++++++++++++++++ src/cpp/model/table/ModelBase.h | 62 ++++++++++ src/cpp/model/table/User.cpp | 10 ++ src/cpp/model/table/User.h | 18 +++ src/cpp/test/TestHash.cpp | 45 ++++++++ src/cpp/test/TestHash.h | 19 +++ src/cpp/test/main.cpp | 1 + src/cpp/test/main.h | 1 + src/cpsp/checkEmail.cpsp | 8 +- src/cpsp/login_header.cpsp | 20 ++++ src/cpsp/updateUserPassword.cpsp | 1 + 32 files changed, 745 insertions(+), 411 deletions(-) delete mode 100644 src/cpp/model/ElopageBuy.cpp delete mode 100644 src/cpp/model/ElopageBuy.h delete mode 100644 src/cpp/model/ModelBase.cpp delete mode 100644 src/cpp/model/ModelBase.h create mode 100644 src/cpp/model/TableControllerBase.cpp create mode 100644 src/cpp/model/TableControllerBase.h create mode 100644 src/cpp/model/table/ElopageBuy.cpp create mode 100644 src/cpp/model/table/ElopageBuy.h create mode 100644 src/cpp/model/table/EmailOptIn.cpp create mode 100644 src/cpp/model/table/EmailOptIn.h create mode 100644 src/cpp/model/table/ModelBase.cpp create mode 100644 src/cpp/model/table/ModelBase.h create mode 100644 src/cpp/model/table/User.cpp create mode 100644 src/cpp/model/table/User.h create mode 100644 src/cpp/test/TestHash.cpp create mode 100644 src/cpp/test/TestHash.h create mode 100644 src/cpsp/login_header.cpsp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bd6ce558..013990906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ FILE(GLOB TASKS "src/cpp/tasks/*.cpp" "src/cpp/tasks/*.h") FILE(GLOB SINGLETON_MANAGER "src/cpp/SingletonManager/*.h" "src/cpp/SingletonManager/*.cpp") FILE(GLOB LIB_SRC "src/cpp/lib/*.h" "src/cpp/lib/*.cpp") FILE(GLOB MODEL "src/cpp/model/*.h" "src/cpp/model/*.cpp") +FILE(GLOB MODEL_TABLE "src/cpp/model/table/*.h" "src/cpp/model/table/*.cpp") FILE(GLOB CRYPTO "src/cpp/Crypto/*.h" "src/cpp/Crypto/*.cpp") FILE(GLOB MAIN "src/cpp/*.cpp" "src/cpp/*.c" "src/cpp/*.h") FILE(GLOB MYSQL "src/cpp/MySQL/*.cpp" "src/cpp/MySQL/*.h" "src/cpp/MySQL/Poco/*.h") @@ -34,7 +35,7 @@ FILE(GLOB TEST "src/cpp/test/*.cpp" "src/cpp/test/*.h") SET(LOCAL_SRCS ${TINF} ${MAIN} ${HTTPInterface} - ${JSONInterface} ${CRYPTO} ${MODEL} + ${JSONInterface} ${CRYPTO} ${MODEL} ${MODEL_TABLE} ${SINGLETON_MANAGER} ${LIB_SRC} ${MYSQL} ${TASKS} ${PROTO_GRADIDO} ) @@ -46,6 +47,7 @@ source_group("proto" FILES ${PROTO_GRADIDO}) source_group("tinf" FILES ${TINF}) source_group("crypto" FILES ${CRYPTO}) source_group("tasks" FILES ${TASKS}) +source_group("model\\table" FILES ${MODEL_TABLE}) source_group("model" FILES ${MODEL}) source_group("mysql" FILES ${MYSQL}) source_group("SingletonManager" FILES ${SINGLETON_MANAGER}) diff --git a/src/cpp/HTTPInterface/CheckEmailPage.cpp b/src/cpp/HTTPInterface/CheckEmailPage.cpp index 3deaa75c0..25cc67fed 100644 --- a/src/cpp/HTTPInterface/CheckEmailPage.cpp +++ b/src/cpp/HTTPInterface/CheckEmailPage.cpp @@ -118,11 +118,24 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: responseStream << "
\n"; responseStream << " \n"; @@ -131,25 +144,25 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: responseStream << "
\n"; responseStream << "
\n"; responseStream << " "; -#line 69 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" +#line 73 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" responseStream << ( getErrorsHtml() ); responseStream << "\n"; responseStream << "
\n"; responseStream << "
\n"; responseStream << "
\n"; responseStream << "
\n"; responseStream << "
\n"; responseStream << "
\n"; responseStream << " \n"; @@ -158,12 +171,12 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: responseStream << "
\n"; responseStream << "
\n"; responseStream << " \n"; @@ -173,51 +186,51 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: responseStream << "
\n"; responseStream << "
\n"; responseStream << " \n"; responseStream << " gettext("Email Verification Code")); responseStream << "\" "; -#line 94 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" +#line 98 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" if(verificationCode) { responseStream << "value=\""; -#line 94 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" +#line 98 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" responseStream << ( verificationCode ); responseStream << "\" "; -#line 94 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" +#line 98 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" } responseStream << ">\n"; responseStream << "
\n"; responseStream << " \n"; responseStream << "
\n"; responseStream << " \n"; responseStream << " \n"; responseStream << "

\n"; responseStream << "\t\t\t\t"; -#line 104 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" +#line 108 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" responseStream << ( langCatalog->gettext("Funktioniert dein E-Mail Verification Code nicht?")); responseStream << "
\n"; responseStream << "\t\t\t\t"; -#line 105 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" +#line 109 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" responseStream << ( langCatalog->gettext("Schicke uns eine E-Mail und wir kümmern uns darum: ")); responseStream << "
\n"; responseStream << " "; -#line 106 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" +#line 110 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp" responseStream << ( langCatalog->gettext("E-Mail an Support schicken")); responseStream << "\n"; responseStream << "\t\t\t

\n"; diff --git a/src/cpp/HTTPInterface/ElopageWebhook.cpp b/src/cpp/HTTPInterface/ElopageWebhook.cpp index 9f9a35b8b..85c1638b7 100644 --- a/src/cpp/HTTPInterface/ElopageWebhook.cpp +++ b/src/cpp/HTTPInterface/ElopageWebhook.cpp @@ -17,7 +17,7 @@ using namespace Poco::Data::Keywords; #include "../tasks/SendEmailTask.h" #include "../model/EmailVerificationCode.h" -#include "../model/ElopageBuy.h" +#include "../model/table/ElopageBuy.h" @@ -211,11 +211,11 @@ int HandleElopageRequestTask::run() } // elopage buy - Poco::AutoPtr elopageBuy(new ElopageBuy(mRequestData)); + Poco::AutoPtr elopageBuy(new model::table::ElopageBuy(mRequestData)); if (elopageBuy->errorCount() > 0) { getErrors(elopageBuy); } - UniLib::controller::TaskPtr saveElopageBuy(new ModelInsertTask(elopageBuy)); + UniLib::controller::TaskPtr saveElopageBuy(new model::table::ModelInsertTask(elopageBuy)); saveElopageBuy->scheduleTask(saveElopageBuy); // check product id @@ -301,10 +301,11 @@ int HandleElopageRequestTask::run() } // email verification code - Poco::AutoPtr emailVerification(new EmailVerificationCode(user_id)); + auto emailVerification = model::EmailVerificationCode::create(user_id); + //Poco::AutoPtr emailVerification(new model::table::EmailOptIn(user_id)); // create email verification code - if (!emailVerification->getCode()) { + if (!emailVerification->getModel()->getCode()) { // exit if email verification code is empty addError(new Error("Email verification", "code is empty, error in random?")); addError(param_error_order_id); @@ -313,7 +314,7 @@ int HandleElopageRequestTask::run() } // write email verification code into db - UniLib::controller::TaskPtr saveEmailVerificationCode(new ModelInsertTask(emailVerification)); + UniLib::controller::TaskPtr saveEmailVerificationCode(new model::table::ModelInsertTask(emailVerification->getModel())); saveEmailVerificationCode->scheduleTask(saveEmailVerificationCode); int noEMail = 0; @@ -344,7 +345,7 @@ int HandleElopageRequestTask::run() std::stringstream ss; ss << "Hallo " << mFirstName << " " << mLastName << "," << std::endl << std::endl; ss << "Du oder jemand anderes hat sich soeben mit dieser E-Mail Adresse bei Gradido registriert. " << std::endl; - ss << "Wenn du es warst, klicke bitte auf den Link: " << ServerConfig::g_serverPath << "/checkEmail/" << emailVerification->getCode() << std::endl; + ss << "Wenn du es warst, klicke bitte auf den Link: " << ServerConfig::g_serverPath << "/checkEmail/" << emailVerification->getModel()->getCode() << std::endl; //ss << "oder kopiere den Code: " << mEmailVerificationCode << " selbst dort hinein." << std::endl; ss << "oder kopiere den obigen Link in Dein Browserfenster." << std::endl; ss << std::endl; diff --git a/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp b/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp index 52a502039..06336635a 100644 --- a/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp +++ b/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp @@ -17,6 +17,7 @@ #include "UpdateUserPasswordPage.h" #include "Error500Page.h" #include "CheckTransactionPage.h" +#include "ResetPassword.h" #include "../SingletonManager/SessionManager.h" @@ -92,6 +93,11 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c pageRequestHandler->setProfiler(timeUsed); return pageRequestHandler; } + if (url_first_part == "/resetPassword") { + auto resetPassword = new ResetPassword; + resetPassword->setProfiler(timeUsed); + return resetPassword; + } if (s) { auto user = s->getUser(); if (s->errorCount() || (!user.isNull() && user->errorCount())) { diff --git a/src/cpp/HTTPInterface/UpdateUserPasswordPage.cpp b/src/cpp/HTTPInterface/UpdateUserPasswordPage.cpp index 6ed7ac7c5..bbde7274b 100644 --- a/src/cpp/HTTPInterface/UpdateUserPasswordPage.cpp +++ b/src/cpp/HTTPInterface/UpdateUserPasswordPage.cpp @@ -58,6 +58,7 @@ void UpdateUserPasswordPage::handleRequest(Poco::Net::HTTPServerRequest& request mSession->getErrors(user); if(-2 == ret || -1 == ret || 1 == ret) { response.redirect(uri_start + "/error500"); + return; } response.redirect(uri_start + "/passphrase"); return; @@ -150,7 +151,7 @@ void UpdateUserPasswordPage::handleRequest(Poco::Net::HTTPServerRequest& request responseStream << "
\n"; responseStream << "\t

Passwort bestimmen

\n"; responseStream << "\t"; -#line 52 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\UpdateUserPassword.cpsp" +#line 53 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\UpdateUserPassword.cpsp" responseStream << ( getErrorsHtml() ); responseStream << "\n"; responseStream << "\t
\t\n"; diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index bc5d45436..91cb3ce40 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -19,7 +19,7 @@ int main(int argc, char** argv) printf("error initing sodium, early exit\n"); return -1; } - ServerConfig::g_versionString = "0.10.0"; + ServerConfig::g_versionString = "0.10.1"; printf("User size: %d Bytes, Session size: %d Bytes\n", sizeof(User), sizeof(Session)); // first check time for crypto diff --git a/src/cpp/model/ElopageBuy.cpp b/src/cpp/model/ElopageBuy.cpp deleted file mode 100644 index 0d0e7a33f..000000000 --- a/src/cpp/model/ElopageBuy.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "ElopageBuy.h" - -using namespace Poco::Data::Keywords; - -const static std::string g_requestFieldsNames[] = { - "product[affiliate_program_id]", "publisher[id]", "order_id", "product_id", - "product[price]", "payer[email]", "publisher[email]", "payment_state", "success_date", "event" }; - -ElopageBuy::ElopageBuy(const Poco::Net::NameValueCollection& elopage_webhook_requestData) - : mPayed(false) -{ - memset(mIDs, 0, ELOPAGE_BUY_MAX * sizeof(Poco::Int32)); - for (int i = 0; i < 5; i++) { - std::string temp = elopage_webhook_requestData.get(g_requestFieldsNames[i], "0"); - //printf("get: %s for field: %s (%d)\n", temp.data(), g_requestFieldsNames[i].data(), i); - try { - if (i == 4) { - mIDs[i+1] = static_cast(round(stof(temp) * 100.0f)); - } - else { - mIDs[i+1] = stoul(temp); - } - } - catch (const std::invalid_argument& ia) {addError(new ParamError("ElopageBuy", "parse string to number, invalid argument", ia.what()));} - catch (const std::out_of_range& oor) { addError(new ParamError("ElopageBuy", "parse string to number, Out of Range error", oor.what()));} - catch (const std::logic_error & ler) { addError(new ParamError("ElopageBuy", "parse string to number, Logical error", ler.what()));} - catch (...) {addError(new Error("ElopageBuy", "parse string to number, unknown error"));} - } - mPayerEmail = elopage_webhook_requestData.get(g_requestFieldsNames[5], ""); - mPublisherEmail = elopage_webhook_requestData.get(g_requestFieldsNames[6], ""); - std::string payed = elopage_webhook_requestData.get(g_requestFieldsNames[7], ""); - // payment_state = paid - if (payed == "paid") mPayed = true; - - mSuccessDate = parseElopageDate(elopage_webhook_requestData.get(g_requestFieldsNames[8], "")); - mEvent = elopage_webhook_requestData.get(g_requestFieldsNames[9], ""); -} - -ElopageBuy::~ElopageBuy() -{ - -} - -/* -ELOPAGE_BUY_AFFILIATE_PROGRAM_ID, -ELOPAGE_BUY_PUBLISHER_ID, -ELOPAGE_BUY_ORDER_ID, -ELOPAGE_BUY_PRODUCT_ID, -ELOPAGE_BUY_PRODUCT_PRICE -*/ - -Poco::Data::Statement ElopageBuy::insertIntoDB(Poco::Data::Session session) -{ - Poco::Data::Statement insert(session); - - lock(); - insert << "INSERT INTO " << getTableName() - << " (affiliate_program_id, publisher_id, order_id, product_id, product_price, payer_email, publisher_email, payed, success_date, event) " - << " VALUES(?,?,?,?,?,?,?,?,?,?)" - , bind(mIDs[ELOPAGE_BUY_AFFILIATE_PROGRAM_ID]), bind(mIDs[ELOPAGE_BUY_PUBLISHER_ID]) - , bind(mIDs[ELOPAGE_BUY_ORDER_ID]), bind(mIDs[ELOPAGE_BUY_PRODUCT_ID]), bind(mIDs[ELOPAGE_BUY_PRODUCT_PRICE]) - , bind(mPayerEmail), bind(mPublisherEmail), bind(mPayed), bind(mSuccessDate), bind(mEvent); - unlock(); - return insert; - -} -Poco::Data::Statement ElopageBuy::updateIntoDB(Poco::Data::Session session) -{ - throw Poco::Exception("ElopageBuy::updateIntoDB not implemented"); -} -Poco::Data::Statement ElopageBuy::loadFromDB(Poco::Data::Session session, std::string& fieldName) -{ -// Poco::Data::Statement select(session); - - throw Poco::Exception("ElopageBuy::loadFromDB not implemented"); - -} \ No newline at end of file diff --git a/src/cpp/model/ElopageBuy.h b/src/cpp/model/ElopageBuy.h deleted file mode 100644 index 5e6174d38..000000000 --- a/src/cpp/model/ElopageBuy.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef GRADIDO_LOGIN_SERVER_MODEL_ELOPAGE_BUY_INCLUDE -#define GRADIDO_LOGIN_SERVER_MODEL_ELOPAGE_BUY_INCLUDE - -/*! - * @author: Dario Rekowski - * - * @date: 31.10.2019 - * - * @brief: Model for handling Elopage publisher - * - */ - -#include "ModelBase.h" -#include "Poco/Types.h" -#include "Poco/Net/NameValueCollection.h" - - -enum ElopageBuyId { - ELOPAGE_BUY_ID, - ELOPAGE_BUY_AFFILIATE_PROGRAM_ID, - ELOPAGE_BUY_PUBLISHER_ID, - ELOPAGE_BUY_ORDER_ID, - ELOPAGE_BUY_PRODUCT_ID, - ELOPAGE_BUY_PRODUCT_PRICE, - - ELOPAGE_BUY_MAX -}; - -class ElopageBuy : public ModelBase -{ -public: - ElopageBuy(const Poco::Net::NameValueCollection& elopage_webhook_requestData); - ~ElopageBuy(); - - // generic db operations - const char* getTableName() { return "elopage_buys"; } - Poco::Data::Statement insertIntoDB(Poco::Data::Session session); - Poco::Data::Statement updateIntoDB(Poco::Data::Session session); - Poco::Data::Statement loadFromDB(Poco::Data::Session session, std::string& fieldName); - - - -protected: - Poco::Int32 mIDs[ELOPAGE_BUY_MAX]; - std::string mPayerEmail; - std::string mPublisherEmail; - bool mPayed; - Poco::DateTime mSuccessDate; - std::string mEvent; -}; - -#endif //GRADIDO_LOGIN_SERVER_MODEL_ELOPAGE_BUY_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/EmailVerificationCode.cpp b/src/cpp/model/EmailVerificationCode.cpp index 7b5b09941..a5f6d0a1b 100644 --- a/src/cpp/model/EmailVerificationCode.cpp +++ b/src/cpp/model/EmailVerificationCode.cpp @@ -2,86 +2,45 @@ #include "sodium.h" -using namespace Poco::Data::Keywords; +namespace model { -EmailVerificationCode::EmailVerificationCode(int user_id) - : mUserId(user_id), mEmailVerificationCode(0) -{ - createEmailVerificationCode(); -} - -EmailVerificationCode::EmailVerificationCode() - : mUserId(0), mEmailVerificationCode(0) -{ - -} - -EmailVerificationCode::~EmailVerificationCode() -{ - -} - - -void EmailVerificationCode::createEmailVerificationCode() -{ - uint32_t* code_p = (uint32_t*)&mEmailVerificationCode; - for (int i = 0; i < sizeof(mEmailVerificationCode) / 4; i++) { - code_p[i] = randombytes_random(); + EmailVerificationCode::EmailVerificationCode(table::EmailOptIn* dbModel) + { + mDBModel = dbModel; } -} -Poco::Data::Statement EmailVerificationCode::insertIntoDB(Poco::Data::Session session) -{ - Poco::Data::Statement insert(session); + EmailVerificationCode::~EmailVerificationCode() + { - lock(); - insert << "INSERT INTO " << getTableName() - << " (user_id, verification_code) VALUES(?,?)" - , bind(mUserId), bind(mEmailVerificationCode); - unlock(); - return insert; -} + } -Poco::Data::Statement EmailVerificationCode::updateIntoDB(Poco::Data::Session session) -{ - throw Poco::Exception("EmailVerificationCode::updateIntoDB not implemented"); -} + /* + Poco::AutoPtr EmailVerificationCode::getModel() + { + lock("EmailVerificationCode::getModel"); + table::EmailOptIn* result = static_cast(mDBModel.get()); + unlock(); + return Poco::AutoPtr(result, true); + } + */ + // --------------- static members ----------------------------- -Poco::Data::Statement EmailVerificationCode::loadFromDB(Poco::Data::Session session, std::string& fieldName) -{ - Poco::Data::Statement select(session); + Poco::AutoPtr EmailVerificationCode::create(int user_id) + { + auto code = createEmailVerificationCode(); + auto db = new table::EmailOptIn(code, user_id); + auto result = new EmailVerificationCode(db); + return Poco::AutoPtr(result); + } - select << "SELECT user_id, verification_code FROM " << getTableName() - << " where " << fieldName << " = ?" - , into(mUserId), into(mEmailVerificationCode); - - return select; -} - -/* -Poco::Data::Statement select(session); -int email_checked = 0; -select << "SELECT email, first_name, last_name, password, pubkey, email_checked from users where id = ?", -into(mEmail), into(mFirstName), into(mLastName), into(mPasswordHashed), into(pubkey), into(email_checked), use(user_id); -try { -auto result = select.execute(); -int zahl = 1; -if (result == 1) { - -if (!pubkey.isNull()) { -auto pubkey_value = pubkey.value(); -size_t hexSize = pubkey_value.size() * 2 + 1; -char* hexString = (char*)malloc(hexSize); -memset(hexString, 0, hexSize); -sodium_bin2hex(hexString, hexSize, pubkey_value.content().data(), pubkey_value.size()); -mPublicHex = hexString; -free(hexString); -} -if (email_checked != 0) mEmailChecked = true; -} -} -catch (Poco::Exception& ex) { -addError(new ParamError("User::User", "mysql error", ex.displayText().data())); -} -*/ \ No newline at end of file + Poco::UInt64 EmailVerificationCode::createEmailVerificationCode() + { + Poco::UInt64 resultCode; + uint32_t* code_p = (uint32_t*)&resultCode; + for (int i = 0; i < sizeof(resultCode) / 4; i++) { + code_p[i] = randombytes_random(); + } + return resultCode; + } +} \ No newline at end of file diff --git a/src/cpp/model/EmailVerificationCode.h b/src/cpp/model/EmailVerificationCode.h index 0baf88038..1b78fc9a9 100644 --- a/src/cpp/model/EmailVerificationCode.h +++ b/src/cpp/model/EmailVerificationCode.h @@ -1,33 +1,26 @@ #ifndef GRADIDO_LOGIN_SERVER_MODEL_EMAIL_VERIFICATION_CODE_INCLUDE #define GRADIDO_LOGIN_SERVER_MODEL_EMAIL_VERIFICATION_CODE_INCLUDE -#define EMAIL_VERIFICATION_CODE_SIZE 8 +#include "table/EmailOptIn.h" -#include "ModelBase.h" -#include "Poco/Types.h" +#include "TableControllerBase.h" +namespace model { + class EmailVerificationCode : public TableControllerBase + { + public: + + ~EmailVerificationCode(); -class EmailVerificationCode : public ModelBase -{ -public: - EmailVerificationCode(int user_id); - EmailVerificationCode(); - ~EmailVerificationCode(); + static Poco::AutoPtr create(int user_id); + inline Poco::AutoPtr getModel() { return _getModel(); } - // generic db operations - const char* getTableName() { return "email_opt_in"; } - Poco::Data::Statement insertIntoDB(Poco::Data::Session session); - Poco::Data::Statement updateIntoDB(Poco::Data::Session session); - Poco::Data::Statement loadFromDB(Poco::Data::Session session, std::string& fieldName); - + protected: + EmailVerificationCode(table::EmailOptIn* dbModel); + static Poco::UInt64 createEmailVerificationCode(); - inline Poco::UInt64 getCode() const { return mEmailVerificationCode; } -protected: - void createEmailVerificationCode(); - - // data type must be a multiple of 4 - Poco::UInt64 mEmailVerificationCode; - int mUserId; -}; + //table::EmailOptIn* mDBModel; + }; +} #endif //GRADIDO_LOGIN_SERVER_MODEL_EMAIL_VERIFICATION_CODE_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/ModelBase.cpp b/src/cpp/model/ModelBase.cpp deleted file mode 100644 index 925f696e0..000000000 --- a/src/cpp/model/ModelBase.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "ModelBase.h" -#include "sodium.h" - -#include "../ServerConfig.h" - -#include "../SingletonManager/ConnectionManager.h" - -#include "Poco/URI.h" - -ModelInsertTask::ModelInsertTask(Poco::AutoPtr model) - : UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model) -{ -#ifdef _UNI_LIB_DEBUG - setName(model->getTableName()); -#endif -} - -int ModelInsertTask::run() -{ - auto session = ConnectionManager::getInstance()->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); - auto insert = mModel->insertIntoDB(session); - - try { - insert.execute(); - } - catch (Poco::Exception& ex) { - mModel->lock(); - mModel->addError(new ParamError(mModel->getTableName(), "mysql error by inserting", ex.displayText().data())); - mModel->unlock(); - } - return 0; -} - -// --------------------------------------------------------------------------------------------------- - -void ModelBase::duplicate() -{ - lock(); - mReferenceCount++; - //printf("[ModelBase::duplicate] new value: %d\n", mReferenceCount); - unlock(); -} - -void ModelBase::release() -{ - lock(); - mReferenceCount--; - //printf("[ModelBase::release] new value: %d\n", mReferenceCount); - if (0 == mReferenceCount) { - unlock(); - delete this; - return; - } - unlock(); - -} - -Poco::DateTime ModelBase::parseElopageDate(std::string dateString) -{ - std::string decodedDateString = ""; - Poco::URI::decode(dateString, decodedDateString); - - struct tm * parsedTime; - // used because localtime return an internal pointer, not thread safe - Poco::Mutex& timeMutex = ServerConfig::g_TimeMutex; - - int year, month, day, hour, minute, second; - // ex: 2009-10-29 - if (sscanf(decodedDateString.data(), "%d-%d-%dT%d:%dZ", &year, &month, &day, &hour, &minute) != EOF) { - time_t rawTime; - time(&rawTime); - - // static, used for every thread - timeMutex.lock(); - parsedTime = localtime(&rawTime); - - // tm_year is years since 1900 - parsedTime->tm_year = year - 1900; - // tm_months is months since january - parsedTime->tm_mon = month - 1; - parsedTime->tm_mday = day; - parsedTime->tm_hour = hour; - parsedTime->tm_min = minute; - parsedTime->tm_sec = 0; - - rawTime = mktime(parsedTime); - timeMutex.unlock(); - // rawTime is in seconds, poco timestamp in microseconds - return Poco::DateTime(Poco::Timestamp(rawTime* 1000000)); - } - - return Poco::DateTime(Poco::Timestamp()); -} \ No newline at end of file diff --git a/src/cpp/model/ModelBase.h b/src/cpp/model/ModelBase.h deleted file mode 100644 index acee13bd6..000000000 --- a/src/cpp/model/ModelBase.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE -#define GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE - -#include "Poco/Data/Session.h" - -#include "../lib/MultithreadContainer.h" -#include "../tasks/CPUTask.h" - -#include "../MySQL/MysqlTable.h" - - - -class ModelBase : public UniLib::lib::MultithreadContainer, public ErrorList -{ -public: - ModelBase(int id) :mID(id), mReferenceCount(1) {} - ModelBase() : mID(0), mReferenceCount(1) {} - - virtual const char* getTableName() = 0; - virtual Poco::Data::Statement insertIntoDB(Poco::Data::Session session) = 0; - virtual Poco::Data::Statement updateIntoDB(Poco::Data::Session session) = 0; - virtual Poco::Data::Statement loadFromDB(Poco::Data::Session session, std::string& fieldName) = 0; - virtual bool executeLoadFromDB(Poco::Data::Statement select) { return select.execute() == 1; }; - - inline void setID(int id) { lock(); mID = id; unlock(); } - inline int getID() { lock(); int id = mID; unlock(); return id; } - - static Poco::DateTime parseElopageDate(std::string dateString); - - // for poco auto ptr - void duplicate(); - void release(); -protected: - int mID; - - // for poco auto ptr - int mReferenceCount; - -}; - -class ModelInsertTask : public UniLib::controller::CPUTask -{ -public: - ModelInsertTask(Poco::AutoPtr model); - - int run(); - const char* getResourceType() const { return "ModelInsertTask"; }; - -protected: - Poco::AutoPtr mModel; - -}; - -#endif //GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/Session.cpp b/src/cpp/model/Session.cpp index b0228e74d..440138f7e 100644 --- a/src/cpp/model/Session.cpp +++ b/src/cpp/model/Session.cpp @@ -242,6 +242,27 @@ bool Session::createUser(const std::string& first_name, const std::string& last_ return true; } +bool Session::ifUserExist(const std::string& email) +{ + auto em = ErrorManager::getInstance(); + const char* funcName = "Session::ifUserExist"; + auto dbConnection = ConnectionManager::getInstance()->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); + Poco::Data::Statement select(dbConnection); + bool emailChecked = false; + int userId = 0; + select << "SELECT email_checked, id from users where email = ? and email_checked = 1", + into(emailChecked), into(userId), useRef(email); + + try { + if(select.execute() == 1) return true; + } + catch (Poco::Exception& ex) { + em->addError(new ParamError(funcName, "select user from email verification code mysql error ", ex.displayText().data())); + em->sendErrorsAsEmail(); + } + return false; +} + int Session::updateEmailVerification(Poco::UInt64 emailVerificationCode) { const static char* funcName = "Session::updateEmailVerification"; diff --git a/src/cpp/model/Session.h b/src/cpp/model/Session.h index a36b53b19..452d8859f 100644 --- a/src/cpp/model/Session.h +++ b/src/cpp/model/Session.h @@ -59,6 +59,7 @@ public: bool createUser(const std::string& first_name, const std::string& last_name, const std::string& email, const std::string& password); // TODO: check if email exist and if not, fake waiting on password hashing with profiled times of real password hashing UserStates loadUser(const std::string& email, const std::string& password); + bool ifUserExist(const std::string& email); inline void setUser(Poco::AutoPtr user) { mSessionUser = user; } @@ -73,6 +74,7 @@ public: int updateEmailVerification(Poco::UInt64 emailVerificationCode); + Poco::Net::HTTPCookie getLoginCookie(); diff --git a/src/cpp/model/TableControllerBase.cpp b/src/cpp/model/TableControllerBase.cpp new file mode 100644 index 000000000..09eab6798 --- /dev/null +++ b/src/cpp/model/TableControllerBase.cpp @@ -0,0 +1,44 @@ +#include "TableControllerBase.h" + +#include + +namespace model { + + TableControllerBase::TableControllerBase() + : mReferenceCount(1) + { + + } + + + TableControllerBase::~TableControllerBase() + { + lock("TableControllerBase::deconstruct"); + assert(0 == mReferenceCount); + + unlock(); + } + + void TableControllerBase::duplicate() + { + lock("TableControllerBase::duplicate"); + mReferenceCount++; + //printf("[ModelBase::duplicate] new value: %d\n", mReferenceCount); + unlock(); + } + + void TableControllerBase::release() + { + lock("TableControllerBase::release"); + mReferenceCount--; + //printf("[ModelBase::release] new value: %d\n", mReferenceCount); + if (0 == mReferenceCount) { + unlock(); + delete this; + return; + } + unlock(); + + } + +} \ No newline at end of file diff --git a/src/cpp/model/TableControllerBase.h b/src/cpp/model/TableControllerBase.h new file mode 100644 index 000000000..ebd18fa55 --- /dev/null +++ b/src/cpp/model/TableControllerBase.h @@ -0,0 +1,45 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_CONTROLLER_BASE_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_CONTROLLER_BASE_INCLUDE + +#include "../lib/MultithreadContainer.h" +#include "Poco/AutoPtr.h" +#include "table/ModelBase.h" + +namespace model { + class TableControllerBase : protected UniLib::lib::MultithreadContainer + { + public: + TableControllerBase(); + virtual ~TableControllerBase(); + + + + // for poco auto ptr + void duplicate(); + void release(); + protected: + + template + Poco::AutoPtr _getModel(); + + // for poco auto ptr + int mReferenceCount; + + // + Poco::AutoPtr mDBModel; + }; + + // ****** template function declarations *************** + + template + Poco::AutoPtr TableControllerBase::_getModel() { + // TODO: Maybe update name for error search + lock("TableControllerBase::getModel"); + T* result = static_cast(mDBModel.get()); + unlock(); + return Poco::AutoPtr(result, true); + } + +} + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_CONTROLLER_BASE_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/User.h b/src/cpp/model/User.h index f814a686e..58e3adddf 100644 --- a/src/cpp/model/User.h +++ b/src/cpp/model/User.h @@ -3,7 +3,8 @@ #include "../Crypto/KeyPair.h" #include -#include "ModelBase.h" +//#include "ModelBase.h" +#include "../lib/ErrorList.h" #include "Poco/Thread.h" #include "Poco/Types.h" diff --git a/src/cpp/model/table/ElopageBuy.cpp b/src/cpp/model/table/ElopageBuy.cpp new file mode 100644 index 000000000..80bbad3ca --- /dev/null +++ b/src/cpp/model/table/ElopageBuy.cpp @@ -0,0 +1,82 @@ +#include "ElopageBuy.h" + +using namespace Poco::Data::Keywords; + +namespace model { + namespace table { + const static std::string g_requestFieldsNames[] = { + "product[affiliate_program_id]", "publisher[id]", "order_id", "product_id", + "product[price]", "payer[email]", "publisher[email]", "payment_state", "success_date", "event" }; + + ElopageBuy::ElopageBuy(const Poco::Net::NameValueCollection& elopage_webhook_requestData) + : mPayed(false) + { + memset(mIDs, 0, ELOPAGE_BUY_MAX * sizeof(Poco::Int32)); + for (int i = 0; i < 5; i++) { + std::string temp = elopage_webhook_requestData.get(g_requestFieldsNames[i], "0"); + //printf("get: %s for field: %s (%d)\n", temp.data(), g_requestFieldsNames[i].data(), i); + try { + if (i == 4) { + mIDs[i + 1] = static_cast(round(stof(temp) * 100.0f)); + } + else { + mIDs[i + 1] = stoul(temp); + } + } + catch (const std::invalid_argument& ia) { addError(new ParamError("ElopageBuy", "parse string to number, invalid argument", ia.what())); } + catch (const std::out_of_range& oor) { addError(new ParamError("ElopageBuy", "parse string to number, Out of Range error", oor.what())); } + catch (const std::logic_error & ler) { addError(new ParamError("ElopageBuy", "parse string to number, Logical error", ler.what())); } + catch (...) { addError(new Error("ElopageBuy", "parse string to number, unknown error")); } + } + mPayerEmail = elopage_webhook_requestData.get(g_requestFieldsNames[5], ""); + mPublisherEmail = elopage_webhook_requestData.get(g_requestFieldsNames[6], ""); + std::string payed = elopage_webhook_requestData.get(g_requestFieldsNames[7], ""); + // payment_state = paid + if (payed == "paid") mPayed = true; + + mSuccessDate = parseElopageDate(elopage_webhook_requestData.get(g_requestFieldsNames[8], "")); + mEvent = elopage_webhook_requestData.get(g_requestFieldsNames[9], ""); + } + + ElopageBuy::~ElopageBuy() + { + + } + + /* + ELOPAGE_BUY_AFFILIATE_PROGRAM_ID, + ELOPAGE_BUY_PUBLISHER_ID, + ELOPAGE_BUY_ORDER_ID, + ELOPAGE_BUY_PRODUCT_ID, + ELOPAGE_BUY_PRODUCT_PRICE + */ + + Poco::Data::Statement ElopageBuy::insertIntoDB(Poco::Data::Session session) + { + Poco::Data::Statement insert(session); + + lock(); + insert << "INSERT INTO " << getTableName() + << " (affiliate_program_id, publisher_id, order_id, product_id, product_price, payer_email, publisher_email, payed, success_date, event) " + << " VALUES(?,?,?,?,?,?,?,?,?,?)" + , bind(mIDs[ELOPAGE_BUY_AFFILIATE_PROGRAM_ID]), bind(mIDs[ELOPAGE_BUY_PUBLISHER_ID]) + , bind(mIDs[ELOPAGE_BUY_ORDER_ID]), bind(mIDs[ELOPAGE_BUY_PRODUCT_ID]), bind(mIDs[ELOPAGE_BUY_PRODUCT_PRICE]) + , bind(mPayerEmail), bind(mPublisherEmail), bind(mPayed), bind(mSuccessDate), bind(mEvent); + unlock(); + return insert; + + } + Poco::Data::Statement ElopageBuy::updateIntoDB(Poco::Data::Session session) + { + throw Poco::Exception("ElopageBuy::updateIntoDB not implemented"); + } + Poco::Data::Statement ElopageBuy::loadFromDB(Poco::Data::Session session, std::string& fieldName) + { + // Poco::Data::Statement select(session); + + throw Poco::Exception("ElopageBuy::loadFromDB not implemented"); + + } + } +} + diff --git a/src/cpp/model/table/ElopageBuy.h b/src/cpp/model/table/ElopageBuy.h new file mode 100644 index 000000000..f70dfa096 --- /dev/null +++ b/src/cpp/model/table/ElopageBuy.h @@ -0,0 +1,57 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_ELOPAGE_BUY_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_ELOPAGE_BUY_INCLUDE + +/*! + * @author: Dario Rekowski + * + * @date: 31.10.2019 + * + * @brief: Model for handling Elopage publisher + * + */ + +#include "ModelBase.h" +#include "Poco/Types.h" +#include "Poco/Net/NameValueCollection.h" + +namespace model { + namespace table { + enum ElopageBuyId { + ELOPAGE_BUY_ID, + ELOPAGE_BUY_AFFILIATE_PROGRAM_ID, + ELOPAGE_BUY_PUBLISHER_ID, + ELOPAGE_BUY_ORDER_ID, + ELOPAGE_BUY_PRODUCT_ID, + ELOPAGE_BUY_PRODUCT_PRICE, + + ELOPAGE_BUY_MAX + }; + + class ElopageBuy : public ModelBase + { + public: + ElopageBuy(const Poco::Net::NameValueCollection& elopage_webhook_requestData); + ~ElopageBuy(); + + // generic db operations + const char* getTableName() { return "elopage_buys"; } + Poco::Data::Statement insertIntoDB(Poco::Data::Session session); + Poco::Data::Statement updateIntoDB(Poco::Data::Session session); + Poco::Data::Statement loadFromDB(Poco::Data::Session session, std::string& fieldName); + + + + protected: + Poco::Int32 mIDs[ELOPAGE_BUY_MAX]; + std::string mPayerEmail; + std::string mPublisherEmail; + bool mPayed; + Poco::DateTime mSuccessDate; + std::string mEvent; + }; + } +} + + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_ELOPAGE_BUY_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/table/EmailOptIn.cpp b/src/cpp/model/table/EmailOptIn.cpp new file mode 100644 index 000000000..8d09bc054 --- /dev/null +++ b/src/cpp/model/table/EmailOptIn.cpp @@ -0,0 +1,58 @@ +#include "EmailOptIn.h" + +#include "sodium.h" + +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() + : mUserId(0), mEmailVerificationCode(0) + { + + } + + EmailOptIn::~EmailOptIn() + { + + } + + + Poco::Data::Statement EmailOptIn::insertIntoDB(Poco::Data::Session session) + { + Poco::Data::Statement insert(session); + + lock(); + insert << "INSERT INTO " << getTableName() + << " (user_id, verification_code) VALUES(?,?)" + , bind(mUserId), bind(mEmailVerificationCode); + unlock(); + return insert; + } + + Poco::Data::Statement EmailOptIn::updateIntoDB(Poco::Data::Session session) + { + throw Poco::Exception("EmailVerificationCode::updateIntoDB not implemented"); + } + + + Poco::Data::Statement EmailOptIn::loadFromDB(Poco::Data::Session session, std::string& fieldName) + { + Poco::Data::Statement select(session); + + select << "SELECT user_id, verification_code FROM " << getTableName() + << " where " << fieldName << " = ?" + , into(mUserId), into(mEmailVerificationCode); + + return select; + } + } +} + + diff --git a/src/cpp/model/table/EmailOptIn.h b/src/cpp/model/table/EmailOptIn.h new file mode 100644 index 000000000..fc2a9d79c --- /dev/null +++ b/src/cpp/model/table/EmailOptIn.h @@ -0,0 +1,38 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_EMAIL_OPT_IN_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_EMAIL_OPT_IN_INCLUDE + +#define EMAIL_VERIFICATION_CODE_SIZE 8 + +#include "ModelBase.h" +#include "Poco/Types.h" + +namespace model { + namespace table { + class EmailOptIn : public ModelBase + { + public: + EmailOptIn(const Poco::UInt64& code, int user_id); + EmailOptIn(); + ~EmailOptIn(); + + // generic db operations + const char* getTableName() { return "email_opt_in"; } + Poco::Data::Statement insertIntoDB(Poco::Data::Session session); + Poco::Data::Statement updateIntoDB(Poco::Data::Session session); + Poco::Data::Statement loadFromDB(Poco::Data::Session session, std::string& fieldName); + + + inline Poco::UInt64 getCode() const { return mEmailVerificationCode; } + protected: + + + // data type must be a multiple of 4 + Poco::UInt64 mEmailVerificationCode; + int mUserId; + }; + + } +} + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_EMAIL_OPT_IN_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/table/ModelBase.cpp b/src/cpp/model/table/ModelBase.cpp new file mode 100644 index 000000000..6b0676ac7 --- /dev/null +++ b/src/cpp/model/table/ModelBase.cpp @@ -0,0 +1,106 @@ +#include "ModelBase.h" +#include "sodium.h" + +#include "../../ServerConfig.h" + +#include "../../SingletonManager/ConnectionManager.h" + +#include "Poco/URI.h" + +namespace model { + namespace table { + + ModelInsertTask::ModelInsertTask(Poco::AutoPtr model) + : UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model) + { +#ifdef _UNI_LIB_DEBUG + setName(model->getTableName()); +#endif + } + + + int ModelInsertTask::run() + { + auto session = ConnectionManager::getInstance()->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); + auto insert = mModel->insertIntoDB(session); + + try { + insert.execute(); + } + catch (Poco::Exception& ex) { + mModel->lock(); + mModel->addError(new ParamError(mModel->getTableName(), "mysql error by inserting", ex.displayText().data())); + mModel->unlock(); + } + return 0; + } + + // --------------------------------------------------------------------------------------------------- + + ModelBase::~ModelBase() + { + lock("~ModelBase"); + assert(0 == mReferenceCount); + unlock(); + } + + void ModelBase::duplicate() + { + lock(); + mReferenceCount++; + //printf("[ModelBase::duplicate] new value: %d\n", mReferenceCount); + unlock(); + } + + void ModelBase::release() + { + lock(); + mReferenceCount--; + //printf("[ModelBase::release] new value: %d\n", mReferenceCount); + if (0 == mReferenceCount) { + unlock(); + delete this; + return; + } + unlock(); + + } + + Poco::DateTime ModelBase::parseElopageDate(std::string dateString) + { + std::string decodedDateString = ""; + Poco::URI::decode(dateString, decodedDateString); + + struct tm * parsedTime; + // used because localtime return an internal pointer, not thread safe + Poco::Mutex& timeMutex = ServerConfig::g_TimeMutex; + + int year, month, day, hour, minute, second; + // ex: 2009-10-29 + if (sscanf(decodedDateString.data(), "%d-%d-%dT%d:%dZ", &year, &month, &day, &hour, &minute) != EOF) { + time_t rawTime; + time(&rawTime); + + // static, used for every thread + timeMutex.lock(); + parsedTime = localtime(&rawTime); + + // tm_year is years since 1900 + parsedTime->tm_year = year - 1900; + // tm_months is months since january + parsedTime->tm_mon = month - 1; + parsedTime->tm_mday = day; + parsedTime->tm_hour = hour; + parsedTime->tm_min = minute; + parsedTime->tm_sec = 0; + + rawTime = mktime(parsedTime); + timeMutex.unlock(); + // rawTime is in seconds, poco timestamp in microseconds + return Poco::DateTime(Poco::Timestamp(rawTime * 1000000)); + } + + return Poco::DateTime(Poco::Timestamp()); + } + } +} diff --git a/src/cpp/model/table/ModelBase.h b/src/cpp/model/table/ModelBase.h new file mode 100644 index 000000000..40881e8df --- /dev/null +++ b/src/cpp/model/table/ModelBase.h @@ -0,0 +1,62 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE + +#include "Poco/Data/Session.h" + +#include "../../lib/MultithreadContainer.h" +#include "../../tasks/CPUTask.h" + +#include "../../MySQL/MysqlTable.h" + +namespace model { + namespace table { + + class ModelBase : public UniLib::lib::MultithreadContainer, public ErrorList + { + public: + ModelBase(int id) :mID(id), mReferenceCount(1) {} + ModelBase() : mID(0), mReferenceCount(1) {} + virtual ~ModelBase(); + + virtual const char* getTableName() = 0; + virtual Poco::Data::Statement insertIntoDB(Poco::Data::Session session) = 0; + virtual Poco::Data::Statement updateIntoDB(Poco::Data::Session session) = 0; + virtual Poco::Data::Statement loadFromDB(Poco::Data::Session session, std::string& fieldName) = 0; + virtual bool executeLoadFromDB(Poco::Data::Statement select) { return select.execute() == 1; }; + + + inline void setID(int id) { lock(); mID = id; unlock(); } + inline int getID() { lock(); int id = mID; unlock(); return id; } + + static Poco::DateTime parseElopageDate(std::string dateString); + + // for poco auto ptr + void duplicate(); + void release(); + protected: + int mID; + + // for poco auto ptr + int mReferenceCount; + + }; + + class ModelInsertTask : public UniLib::controller::CPUTask + { + public: + ModelInsertTask(Poco::AutoPtr model); + + int run(); + const char* getResourceType() const { return "ModelInsertTask"; }; + + protected: + Poco::AutoPtr mModel; + + }; + } +} + + + + +#endif //GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE \ No newline at end of file diff --git a/src/cpp/model/table/User.cpp b/src/cpp/model/table/User.cpp new file mode 100644 index 000000000..e8ccfeb1b --- /dev/null +++ b/src/cpp/model/table/User.cpp @@ -0,0 +1,10 @@ +#include "User.h" + +namespace model { + namespace table { + User::User() + { + + } + } +} \ No newline at end of file diff --git a/src/cpp/model/table/User.h b/src/cpp/model/table/User.h new file mode 100644 index 000000000..c83fef84c --- /dev/null +++ b/src/cpp/model/table/User.h @@ -0,0 +1,18 @@ +#ifndef GRADIDO_LOGIN_SERVER_MODEL_TABLE_USER_INCLUDE +#define GRADIDO_LOGIN_SERVER_MODEL_TABLE_USER_INCLUDE + +#include "ModelBase.h" + +namespace model { + namespace table { + class User : ModelBase + { + public: + User(); + protected: + + }; + } +} + +#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_USER_INCLUDE \ No newline at end of file diff --git a/src/cpp/test/TestHash.cpp b/src/cpp/test/TestHash.cpp new file mode 100644 index 000000000..82c41e37e --- /dev/null +++ b/src/cpp/test/TestHash.cpp @@ -0,0 +1,45 @@ +#include "TestHash.h" +#include "../lib/DRHash.h" + +#include + +TestHash::TestHash() +{ + +} + +TestHash::~TestHash() +{ + +} + +int TestHash::init() +{ + return 0; +} + +int TestHash::test() +{ + std::string testEmails[] = { + "a","b", "c", "d", "aa", "ab", + "@", ".d", "gmx", "@gmx", "@gmx.de", + "***REMOVED***", + "***REMOVED***", + "coin-info5@gradido.net", + "coin-info6@gradido.net", + "coin-info8@gradido.net", + "coin-info9@gradido.net", + "coin-info10@gradido.net", + "coin-info11@gradido.net", + "coin-info12@gradido.net" + }; + printf("hashes: \n"); + for (int i = 0; i < 20; i++) { + DHASH id = DRMakeStringHash(testEmails[i].data(), testEmails[i].size()); + //printf("%s: %lu\n", testEmails[i].data(), id); + //"***REMOVED***" => 1211212 + printf("\"%s\" => %lu,\n", testEmails[i].data(), id); + } + return 0; +} + diff --git a/src/cpp/test/TestHash.h b/src/cpp/test/TestHash.h new file mode 100644 index 000000000..6157195d3 --- /dev/null +++ b/src/cpp/test/TestHash.h @@ -0,0 +1,19 @@ +#ifndef __GRADIDO_LOGIN_SERVER_TEST_HASH_ +#define __GRADIDO_LOGIN_SERVER_TEST_HASH_ + +#include "Test.h" + +class TestHash : public Test +{ +public: + TestHash(); + ~TestHash(); + //! \return 0 if init okay, else return != 0 + int init(); + + //! \return 0 if okay, else return != 0 + int test(); + const char* getName() { return "TestHash"; }; +}; + +#endif //__GRADIDO_LOGIN_SERVER_TEST_HASH_ \ No newline at end of file diff --git a/src/cpp/test/main.cpp b/src/cpp/test/main.cpp index a8e3ab6a4..3f9e94096 100644 --- a/src/cpp/test/main.cpp +++ b/src/cpp/test/main.cpp @@ -7,6 +7,7 @@ std::list gTests; void fillTests() { gTests.push_back(new TestTasks()); + gTests.push_back(new TestHash()); // gTests.push_back(new LoginTest()); } diff --git a/src/cpp/test/main.h b/src/cpp/test/main.h index 06d8ecf35..ac57bc341 100644 --- a/src/cpp/test/main.h +++ b/src/cpp/test/main.h @@ -1,2 +1,3 @@ #include "TestTasks.h" +#include "TestHash.h" diff --git a/src/cpsp/checkEmail.cpsp b/src/cpsp/checkEmail.cpsp index e531e3243..e963b1879 100644 --- a/src/cpsp/checkEmail.cpsp +++ b/src/cpsp/checkEmail.cpsp @@ -57,8 +57,12 @@ enum PageState
diff --git a/src/cpsp/login_header.cpsp b/src/cpsp/login_header.cpsp new file mode 100644 index 000000000..d9d72d856 --- /dev/null +++ b/src/cpsp/login_header.cpsp @@ -0,0 +1,20 @@ +<%@ include file="header.cpsp" %> +
+ +
+
+
+
+ <%= getErrorsHtml() %> +
+
\ No newline at end of file diff --git a/src/cpsp/updateUserPassword.cpsp b/src/cpsp/updateUserPassword.cpsp index e32ca80fb..690d90201 100644 --- a/src/cpsp/updateUserPassword.cpsp +++ b/src/cpsp/updateUserPassword.cpsp @@ -36,6 +36,7 @@ mSession->getErrors(user); if(-2 == ret || -1 == ret || 1 == ret) { response.redirect(uri_start + "/error500"); + return; } response.redirect(uri_start + "/passphrase"); return;