mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
update model structure
This commit is contained in:
parent
80809dd91c
commit
f890cac00d
@ -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})
|
||||
|
||||
@ -118,11 +118,24 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
|
||||
responseStream << "<div class=\"authentication-theme auth-style_1\">\n";
|
||||
responseStream << " <div class=\"row\">\n";
|
||||
responseStream << " <div class=\"col-12 logo-section\">\n";
|
||||
responseStream << " <a href=\"../../index.html\" class=\"logo\">\n";
|
||||
responseStream << " <img src=\"";
|
||||
#line 61 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << " <a href=\"";
|
||||
#line 60 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( ServerConfig::g_php_serverPath );
|
||||
responseStream << "img/logo_schrift.webp\" alt=\"logo\" />\n";
|
||||
responseStream << "\" class=\"logo\">\n";
|
||||
responseStream << " <picture>\n";
|
||||
responseStream << "\t\t\t\t<source srcset=\"";
|
||||
#line 62 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( ServerConfig::g_php_serverPath );
|
||||
responseStream << "img/logo_schrift.webp\" type=\"image/webp\">\n";
|
||||
responseStream << "\t\t\t\t<source srcset=\"";
|
||||
#line 63 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( ServerConfig::g_php_serverPath );
|
||||
responseStream << "img/logo_schrift.png\" type=\"image/png\"> \n";
|
||||
responseStream << "\t\t\t\t<img src=\"";
|
||||
#line 64 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( ServerConfig::g_php_serverPath );
|
||||
responseStream << "img/logo_schrift.png\" alt=\"logo\" />\n";
|
||||
responseStream << "\t\t\t</picture>\n";
|
||||
responseStream << " </a>\n";
|
||||
responseStream << " </div>\n";
|
||||
responseStream << " </div>\n";
|
||||
@ -131,25 +144,25 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
|
||||
responseStream << " <div class=\"grid\">\n";
|
||||
responseStream << " <div class=\"center-ul-container\">\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 << " </div>\n";
|
||||
responseStream << " <div class=\"grid-body\">\n";
|
||||
responseStream << " <form action=\"";
|
||||
#line 72 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 76 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( ServerConfig::g_php_serverPath );
|
||||
responseStream << "account/checkEmail\" method=\"GET\">\n";
|
||||
responseStream << " <div class=\"row pull-right-row\">\n";
|
||||
responseStream << " <div class=\"equel-grid pull-right\">\n";
|
||||
responseStream << " <div class=\"grid-body-small text-center\">\n";
|
||||
responseStream << " <button id=\"flag-england\" name=\"lang-btn\" value=\"en\" title=\"English\" type=\"submit\" ";
|
||||
#line 76 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 80 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
if(lang != LANG_EN) { responseStream << "class=\"btn btn-outline-secondary flag-btn\"";
|
||||
#line 76 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 80 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
}
|
||||
else { responseStream << "class=\"btn btn-secondary disabled flag-btn\" disabled";
|
||||
#line 77 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 81 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
} responseStream << ">\n";
|
||||
responseStream << " <span class=\"flag-england\"></span>\n";
|
||||
responseStream << " </button>\n";
|
||||
@ -158,12 +171,12 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
|
||||
responseStream << " <div class=\"equel-grid pull-right\">\n";
|
||||
responseStream << " <div class=\"grid-body-small text-center\">\n";
|
||||
responseStream << " <button id=\"flag-germany\" name=\"lang-btn\" value=\"de\" title=\"Deutsch\" type=\"submit\" ";
|
||||
#line 84 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 88 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
if(lang != LANG_DE) { responseStream << "class=\"btn btn-outline-secondary flag-btn\"";
|
||||
#line 84 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 88 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
}
|
||||
else { responseStream << "class=\"btn btn-secondary disabled flag-btn\" disabled";
|
||||
#line 85 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 89 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
} responseStream << ">\n";
|
||||
responseStream << " <span class=\"flag-germany\"></span>\n";
|
||||
responseStream << " </button>\n";
|
||||
@ -173,51 +186,51 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
|
||||
responseStream << " <div class=\"item-wrapper\">\n";
|
||||
responseStream << " <div class=\"form-group\">\n";
|
||||
responseStream << " <label for=\"email-verification-code\">";
|
||||
#line 93 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 97 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( langCatalog->gettext("Bitte gebe deinen E-Mail Verification Code ein:"));
|
||||
responseStream << "</label>\n";
|
||||
responseStream << " <input type=\"text\" class=\"form-control\" name=\"email-verification-code\" id=\"email-verification-code\" placeholder=\"";
|
||||
#line 94 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 98 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( langCatalog->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 << " </div>\n";
|
||||
responseStream << " <button type=\"submit\" class=\"btn btn-sm btn-primary\">";
|
||||
#line 96 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 100 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( langCatalog->gettext("Überprüfe Code"));
|
||||
responseStream << "</button>\n";
|
||||
responseStream << " </div>\n";
|
||||
responseStream << " </form>\n";
|
||||
responseStream << " <!--<p class=\"margin-top-10\">\n";
|
||||
responseStream << "\t\t\t\t";
|
||||
#line 100 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 104 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( langCatalog->gettext("Du hast bisher keinen Code erhalten?"));
|
||||
responseStream << "<br> \n";
|
||||
responseStream << "\t\t\t\t";
|
||||
#line 101 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 105 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( langCatalog->gettext("E-Mail erneut zuschicken (in Arbeit)"));
|
||||
responseStream << "\n";
|
||||
responseStream << "\t\t\t </p>-->\n";
|
||||
responseStream << " <p class=\"margin-top-10\">\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 << "<br>\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 << "<br>\n";
|
||||
responseStream << " <b><a href=\"mailto:coin@gradido.net?subject=Invalid E-Mail Verification Code&body=Hallo Dario,%0D%0A%0D%0Amein E-Mail Verification-Code: ";
|
||||
#line 106 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
#line 110 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\checkEmail.cpsp"
|
||||
responseStream << ( verificationCode );
|
||||
responseStream << " funktioniert nicht,%0D%0Akannst du das prüfen?%0D%0A%0D%0AMit freundlichen Grüßen%0D%0A\">";
|
||||
#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 << "</a></b>\n";
|
||||
responseStream << "\t\t\t </p>\n";
|
||||
|
||||
@ -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> elopageBuy(new ElopageBuy(mRequestData));
|
||||
Poco::AutoPtr<model::table::ElopageBuy> 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<EmailVerificationCode> emailVerification(new EmailVerificationCode(user_id));
|
||||
auto emailVerification = model::EmailVerificationCode::create(user_id);
|
||||
//Poco::AutoPtr<model::table::EmailOptIn> 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;
|
||||
|
||||
@ -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())) {
|
||||
|
||||
@ -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 << "<div class=\"grd_container\">\n";
|
||||
responseStream << "\t<h1>Passwort bestimmen</h1>\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<form method=\"POST\">\t\n";
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<Poco::Int32>(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");
|
||||
|
||||
}
|
||||
@ -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
|
||||
@ -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<table::EmailOptIn> EmailVerificationCode::getModel()
|
||||
{
|
||||
lock("EmailVerificationCode::getModel");
|
||||
table::EmailOptIn* result = static_cast<table::EmailOptIn*>(mDBModel.get());
|
||||
unlock();
|
||||
return Poco::AutoPtr<table::EmailOptIn>(result, true);
|
||||
}
|
||||
*/
|
||||
|
||||
// --------------- static members -----------------------------
|
||||
|
||||
Poco::Data::Statement EmailVerificationCode::loadFromDB(Poco::Data::Session session, std::string& fieldName)
|
||||
{
|
||||
Poco::Data::Statement select(session);
|
||||
Poco::AutoPtr<EmailVerificationCode> EmailVerificationCode::create(int user_id)
|
||||
{
|
||||
auto code = createEmailVerificationCode();
|
||||
auto db = new table::EmailOptIn(code, user_id);
|
||||
auto result = new EmailVerificationCode(db);
|
||||
return Poco::AutoPtr<EmailVerificationCode>(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()));
|
||||
}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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<EmailVerificationCode> create(int user_id);
|
||||
inline Poco::AutoPtr<table::EmailOptIn> getModel() { return _getModel<table::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);
|
||||
|
||||
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
|
||||
@ -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<ModelBase> 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());
|
||||
}
|
||||
@ -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<ModelBase> model);
|
||||
|
||||
int run();
|
||||
const char* getResourceType() const { return "ModelInsertTask"; };
|
||||
|
||||
protected:
|
||||
Poco::AutoPtr<ModelBase> mModel;
|
||||
|
||||
};
|
||||
|
||||
#endif //GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE
|
||||
@ -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";
|
||||
|
||||
@ -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> user) { mSessionUser = user; }
|
||||
|
||||
@ -73,6 +74,7 @@ public:
|
||||
int updateEmailVerification(Poco::UInt64 emailVerificationCode);
|
||||
|
||||
|
||||
|
||||
|
||||
Poco::Net::HTTPCookie getLoginCookie();
|
||||
|
||||
|
||||
44
src/cpp/model/TableControllerBase.cpp
Normal file
44
src/cpp/model/TableControllerBase.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "TableControllerBase.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
45
src/cpp/model/TableControllerBase.h
Normal file
45
src/cpp/model/TableControllerBase.h
Normal file
@ -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<class T>
|
||||
Poco::AutoPtr<T> _getModel();
|
||||
|
||||
// for poco auto ptr
|
||||
int mReferenceCount;
|
||||
|
||||
//
|
||||
Poco::AutoPtr <table::ModelBase> mDBModel;
|
||||
};
|
||||
|
||||
// ****** template function declarations ***************
|
||||
|
||||
template<class T>
|
||||
Poco::AutoPtr<T> TableControllerBase::_getModel() {
|
||||
// TODO: Maybe update name for error search
|
||||
lock("TableControllerBase::getModel");
|
||||
T* result = static_cast<T*>(mDBModel.get());
|
||||
unlock();
|
||||
return Poco::AutoPtr<T>(result, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //GRADIDO_LOGIN_SERVER_MODEL_TABLE_CONTROLLER_BASE_INCLUDE
|
||||
@ -3,7 +3,8 @@
|
||||
|
||||
#include "../Crypto/KeyPair.h"
|
||||
#include <string>
|
||||
#include "ModelBase.h"
|
||||
//#include "ModelBase.h"
|
||||
#include "../lib/ErrorList.h"
|
||||
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Types.h"
|
||||
|
||||
82
src/cpp/model/table/ElopageBuy.cpp
Normal file
82
src/cpp/model/table/ElopageBuy.cpp
Normal file
@ -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<Poco::Int32>(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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
57
src/cpp/model/table/ElopageBuy.h
Normal file
57
src/cpp/model/table/ElopageBuy.h
Normal file
@ -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
|
||||
58
src/cpp/model/table/EmailOptIn.cpp
Normal file
58
src/cpp/model/table/EmailOptIn.cpp
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
src/cpp/model/table/EmailOptIn.h
Normal file
38
src/cpp/model/table/EmailOptIn.h
Normal file
@ -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
|
||||
106
src/cpp/model/table/ModelBase.cpp
Normal file
106
src/cpp/model/table/ModelBase.cpp
Normal file
@ -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<ModelBase> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
62
src/cpp/model/table/ModelBase.h
Normal file
62
src/cpp/model/table/ModelBase.h
Normal file
@ -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<ModelBase> model);
|
||||
|
||||
int run();
|
||||
const char* getResourceType() const { return "ModelInsertTask"; };
|
||||
|
||||
protected:
|
||||
Poco::AutoPtr<ModelBase> mModel;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //GRADIDO_LOGIN_SERVER_MODEL_INTERFACE_INCLUDE
|
||||
10
src/cpp/model/table/User.cpp
Normal file
10
src/cpp/model/table/User.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "User.h"
|
||||
|
||||
namespace model {
|
||||
namespace table {
|
||||
User::User()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/cpp/model/table/User.h
Normal file
18
src/cpp/model/table/User.h
Normal file
@ -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
|
||||
45
src/cpp/test/TestHash.cpp
Normal file
45
src/cpp/test/TestHash.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "TestHash.h"
|
||||
#include "../lib/DRHash.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
19
src/cpp/test/TestHash.h
Normal file
19
src/cpp/test/TestHash.h
Normal file
@ -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_
|
||||
@ -7,6 +7,7 @@ std::list<Test*> gTests;
|
||||
void fillTests()
|
||||
{
|
||||
gTests.push_back(new TestTasks());
|
||||
gTests.push_back(new TestHash());
|
||||
// gTests.push_back(new LoginTest());
|
||||
}
|
||||
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
|
||||
#include "TestTasks.h"
|
||||
#include "TestHash.h"
|
||||
|
||||
@ -57,8 +57,12 @@ enum PageState
|
||||
<div class="authentication-theme auth-style_1">
|
||||
<div class="row">
|
||||
<div class="col-12 logo-section">
|
||||
<a href="../../index.html" class="logo">
|
||||
<img src="<%= ServerConfig::g_php_serverPath %>img/logo_schrift.webp" alt="logo" />
|
||||
<a href="<%= ServerConfig::g_php_serverPath %>" class="logo">
|
||||
<picture>
|
||||
<source srcset="<%= ServerConfig::g_php_serverPath %>img/logo_schrift.webp" type="image/webp">
|
||||
<source srcset="<%= ServerConfig::g_php_serverPath %>img/logo_schrift.png" type="image/png">
|
||||
<img src="<%= ServerConfig::g_php_serverPath %>img/logo_schrift.png" alt="logo" />
|
||||
</picture>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
20
src/cpsp/login_header.cpsp
Normal file
20
src/cpsp/login_header.cpsp
Normal file
@ -0,0 +1,20 @@
|
||||
<%@ include file="header.cpsp" %>
|
||||
<div class="authentication-theme auth-style_1">
|
||||
<div class="row">
|
||||
<div class="col-12 logo-section">
|
||||
<a href="<%= ServerConfig::g_php_serverPath %>" class="logo">
|
||||
<picture>
|
||||
<source srcset="<%= ServerConfig::g_php_serverPath %>img/logo_schrift.webp" type="image/webp">
|
||||
<source srcset="<%= ServerConfig::g_php_serverPath %>img/logo_schrift.png" type="image/png">
|
||||
<img src="<%= ServerConfig::g_php_serverPath %>img/logo_schrift.png" alt="logo" />
|
||||
</picture>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-7 col-sm-9 col-11 mx-auto">
|
||||
<div class="grid">
|
||||
<div class="center-ul-container">
|
||||
<%= getErrorsHtml() %>
|
||||
</div>
|
||||
<div class="grid-body">
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user