update cmake for using multiprocessor build with visual studio, work on reset password and new db access classes

This commit is contained in:
Dario 2020-01-06 15:12:18 +01:00
parent 27bf842e6c
commit abef0b1ef1
22 changed files with 206 additions and 36 deletions

View File

@ -97,6 +97,10 @@ set(MYSQL_INCLUDE_DIR "dependencies/mariadb-connector-c/include")
# "I:/FremdCode/C++/ssl/include"
#)
set(CMAKE_CXX_FLAGS "/MP /EHsc")
#set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
#set(CMAKE_CXX_FLAGS_RELEASE "-O3")
else(WIN32)
find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build" REQUIRED)
# set vars for mariadb cmake files
@ -110,8 +114,13 @@ include_directories(
"build/dependencies/mariadb-connector-c/include"
)
endif(WIN32)
target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519})
if(WIN32)
TARGET_LINK_LIBRARIES(Gradido_LoginServer optimized ${MYSQL_LIBRARIES} Shlwapi)
@ -140,6 +149,7 @@ add_executable(Gradido_LoginServer_Test ${LOCAL_SRCS} ${TEST})
target_compile_definitions(Gradido_LoginServer_Test PUBLIC "_TEST_BUILD")
target_link_libraries(Gradido_LoginServer_Test ${CONAN_LIBS} ${IROHA_ED25519})
if(WIN32)
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test optimized ${MYSQL_LIBRARIES} Shlwapi)
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi)

View File

@ -34,7 +34,7 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
Poco::Net::NameValueCollection elopageRequestData;
int breakCount = 100;
while (stream.good() && breakCount > 0) {
char dummy;
// char dummy;
char keyBuffer[30]; memset(keyBuffer, 0, 30);
char valueBuffer[75]; memset(valueBuffer, 0, 75);
/*stream.get(keyBuffer, 30, '=').get(dummy)
@ -195,6 +195,7 @@ int HandleElopageRequestTask::getUserIdFromDB()
}
catch (Poco::Exception& ex) {
addError(new ParamError(__FUNCTION__, "mysql error selecting from db", ex.displayText().data()));
addError(new ParamError(__FUNCTION__, "email: ", mEmail.data()));
}
return user_id;
@ -378,7 +379,9 @@ int HandleElopageRequestTask::run()
addError(param_error_order_id);
sendErrorsAsEmail();
}
delete param_error_order_id;
else {
delete param_error_order_id;
}
return 0;
}

View File

@ -81,12 +81,13 @@ MemoryManager::MemoryManager()
mMemoryPageStacks[1] = new MemoryPageStack(64); // privkey
mMemoryPageStacks[2] = new MemoryPageStack(65); // pubkey hex
mMemoryPageStacks[3] = new MemoryPageStack(96); // privkey encrypted
mMemoryPageStacks[4] = new MemoryPageStack(161); // privkey hex
}
MemoryManager::~MemoryManager()
{
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 5; i++) {
delete mMemoryPageStacks[i];
}
}
@ -98,6 +99,7 @@ Poco::Int8 MemoryManager::getMemoryStackIndex(Poco::UInt16 size)
case 64: return 1;
case 65: return 2;
case 96: return 3;
case 161: return 4;
default: return -1;
}
return -1;

View File

@ -76,7 +76,7 @@ protected:
Poco::Int8 getMemoryStackIndex(Poco::UInt16 size);
MemoryManager();
MemoryPageStack* mMemoryPageStacks[4];
MemoryPageStack* mMemoryPageStacks[5];
};

View File

@ -27,18 +27,18 @@ namespace controller {
// --------------- static members -----------------------------
Poco::AutoPtr<EmailVerificationCode> EmailVerificationCode::create(int user_id)
Poco::AutoPtr<EmailVerificationCode> EmailVerificationCode::create(int user_id, model::table::EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/)
{
auto code = createEmailVerificationCode();
auto db = new model::table::EmailOptIn(code, user_id);
auto db = new model::table::EmailOptIn(code, user_id, type);
auto result = new EmailVerificationCode(db);
return Poco::AutoPtr<EmailVerificationCode>(result);
}
Poco::AutoPtr<EmailVerificationCode> EmailVerificationCode::create()
Poco::AutoPtr<EmailVerificationCode> EmailVerificationCode::create(model::table::EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/)
{
auto code = createEmailVerificationCode();
auto db = new model::table::EmailOptIn(code);
auto db = new model::table::EmailOptIn(code, type);
auto result = new EmailVerificationCode(db);
return Poco::AutoPtr<EmailVerificationCode>(result);
}

View File

@ -12,8 +12,8 @@ namespace controller {
~EmailVerificationCode();
static Poco::AutoPtr<EmailVerificationCode> create(int user_id);
static Poco::AutoPtr<EmailVerificationCode> create();
static Poco::AutoPtr<EmailVerificationCode> create(int user_id, model::table::EmailOptInType type = model::table::EMAIL_OPT_IN_REGISTER);
static Poco::AutoPtr<EmailVerificationCode> create(model::table::EmailOptInType type = model::table::EMAIL_OPT_IN_REGISTER);
inline Poco::AutoPtr<model::table::EmailOptIn> getModel() { return _getModel<model::table::EmailOptIn>(); }
std::string getLink();

View File

@ -15,8 +15,8 @@ namespace controller {
static Poco::AutoPtr<User> create();
static Poco::AutoPtr<User> create(const std::string& email, const std::string& first_name, const std::string& last_name, Poco::UInt64 passwordHashed = 0, std::string languageKey = "de");
inline int load(const std::string& email) { return getModel()->loadFromDB("email", email); }
inline int load(int user_id) { return getModel()->loadFromDB("id", user_id); }
inline size_t load(const std::string& email) { return getModel()->loadFromDB("email", email); }
inline size_t load(int user_id) { return getModel()->loadFromDB("id", user_id); }
int load(const unsigned char* pubkey_array);
inline Poco::AutoPtr<model::table::User> getModel() { return _getModel<model::table::User>(); }

View File

@ -48,6 +48,12 @@ Gradido Login Server\
{
}
Email::Email(AutoPtr<controller::User> user, EmailType type)
: mUser(user), mType(type)
{
}
Email::~Email()
{
while (mAdditionalStringPartSrcs.size() > 0) {

View File

@ -35,6 +35,7 @@ namespace model {
{
public:
Email(AutoPtr<controller::EmailVerificationCode> emailVerification, AutoPtr<controller::User> user, EmailType type);
Email(AutoPtr<controller::User> user, EmailType type);
//! \param errors copy errors into own memory
Email(const std::string& errorHtml, EmailType type);
~Email();

View File

@ -9,6 +9,7 @@
#include "../SingletonManager/SessionManager.h"
#include "../SingletonManager/ConnectionManager.h"
#include "../SingletonManager/ErrorManager.h"
#include "../SingletonManager/EmailManager.h"
#include "../tasks/PrepareEmailTask.h"
#include "../tasks/SendEmailTask.h"
@ -18,6 +19,8 @@
#include "../controller/User.h"
#include "table/ModelBase.h"
#include "sodium.h"
@ -379,9 +382,27 @@ int Session::updateEmailVerification(Poco::UInt64 emailVerificationCode)
return 0;
}
bool Session::createNewEmailVerificationCode()
bool Session::resetPassword(Poco::AutoPtr<controller::User> user, bool passphraseMemorized)
{
mEmailVerificationCodeObject = controller::EmailVerificationCode::create(mNewUser->getModel()->getID());
mNewUser = user;
if (passphraseMemorized) {
mEmailVerificationCodeObject = controller::EmailVerificationCode::create(mNewUser->getModel()->getID(), model::table::EMAIL_OPT_IN_RESET_PASSWORD);
auto emailVerificationModel = mEmailVerificationCodeObject->getModel();
UniLib::controller::TaskPtr insertEmailVerificationCode(
new model::table::ModelInsertTask(emailVerificationModel, true)
);
insertEmailVerificationCode->scheduleTask(insertEmailVerificationCode);
UniLib::controller::TaskPtr sendEmail(new SendEmailTask(
new model::Email(mEmailVerificationCodeObject, mNewUser, model::EMAIL_USER_RESET_PASSWORD),
ServerConfig::g_CPUScheduler, 1)
);
sendEmail->setParentTaskPtrInArray(insertEmailVerificationCode, 0);
sendEmail->scheduleTask(sendEmail);
}
else {
EmailManager::getInstance()->addEmail(new model::Email(user, model::EMAIL_ADMIN_RESET_PASSWORD_REQUEST_WITHOUT_MEMORIZED_PASSPHRASE));
}
return true;
}

View File

@ -90,7 +90,8 @@ public:
//! 0 = ok
int updateEmailVerification(Poco::UInt64 emailVerificationCode);
bool createNewEmailVerificationCode();
// called from page with same name
bool resetPassword(Poco::AutoPtr<controller::User> user, bool passphraseMemorized);
Poco::Net::HTTPCookie getLoginCookie();

View File

@ -9,6 +9,8 @@
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE
#pragma warning(disable:4800)
#include "../lib/ErrorList.h"
#include "../proto/gradido/BasicTypes.pb.h"
#include "../SingletonManager/MemoryManager.h"

View File

@ -9,6 +9,8 @@
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE
#pragma warning(disable:4800)
#include "TransactionBase.h"
#include "../proto/gradido/TransactionCreation.pb.h"
#include "User.h"

View File

@ -9,6 +9,8 @@
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE
#pragma warning(disable:4800)
#include "TransactionBase.h"
#include "../proto/gradido/Transfer.pb.h"

View File

@ -1,4 +1,5 @@
#include "ElopageBuy.h"
#include "Poco/DateTimeFormatter.h"
using namespace Poco::Data::Keywords;
@ -66,6 +67,22 @@ namespace model {
return insert;
}
std::string ElopageBuy::toString()
{
std::stringstream ss;
ss << "affiliate program id: " << mIDs[ELOPAGE_BUY_AFFILIATE_PROGRAM_ID] << std::endl;
ss << "publisher id: " << mIDs[ELOPAGE_BUY_PUBLISHER_ID] << std::endl;
ss << "order id: " << mIDs[ELOPAGE_BUY_ORDER_ID] << std::endl;
ss << "product id: " << mIDs[ELOPAGE_BUY_PRODUCT_ID] << std::endl;
ss << "product price: " << mIDs[ELOPAGE_BUY_PRODUCT_PRICE] << std::endl;
ss << "payer email: " << mPayerEmail << std::endl;
ss << "publisher email: " << mPublisherEmail << std::endl;
ss << "payed: " << mPayed << std::endl;
ss << "success date: " << Poco::DateTimeFormatter::format(mSuccessDate, "%d.%m.%Y %H:%M:%S") << std::endl;
ss << "event: " << mEvent << std::endl;
return ss.str();
}
Poco::Data::Statement ElopageBuy::_loadFromDB(Poco::Data::Session session, const std::string& fieldName)
{

View File

@ -36,6 +36,7 @@ namespace model {
// generic db operations
const char* getTableName() { return "elopage_buys"; }
std::string toString();
protected:
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);

View File

@ -6,14 +6,14 @@ using namespace Poco::Data::Keywords;
namespace model {
namespace table {
EmailOptIn::EmailOptIn(const Poco::UInt64& code, int user_id)
: mUserId(user_id), mEmailVerificationCode(code)
EmailOptIn::EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/)
: mUserId(user_id), mEmailVerificationCode(code), mType(type)
{
}
EmailOptIn::EmailOptIn(const Poco::UInt64& code)
: mUserId(0), mEmailVerificationCode(code)
EmailOptIn::EmailOptIn(const Poco::UInt64& code, EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/)
: mUserId(0), mEmailVerificationCode(code), mType(type)
{
}
@ -36,8 +36,8 @@ namespace model {
lock();
insert << "INSERT INTO " << getTableName()
<< " (user_id, verification_code) VALUES(?,?)"
, bind(mUserId), bind(mEmailVerificationCode);
<< " (user_id, verification_code, email_opt_in_type_id) VALUES(?,?,?))"
, bind(mUserId), bind(mEmailVerificationCode), bind(mType);
unlock();
return insert;
}
@ -47,12 +47,33 @@ namespace model {
{
Poco::Data::Statement select(session);
select << "SELECT user_id, verification_code FROM " << getTableName()
int iType = 0;
select << "SELECT user_id, verification_code, email_opt_in_type_id FROM " << getTableName()
<< " where " << fieldName << " = ?"
, into(mUserId), into(mEmailVerificationCode);
, into(mUserId), into(mEmailVerificationCode), into(iType);
mType = static_cast<EmailOptInType>(iType);
return select;
}
std::string EmailOptIn::toString()
{
std::stringstream ss;
ss << "code: " << mEmailVerificationCode << std::endl;
ss << "user_id: " << mUserId << std::endl;
ss << "type: " << typeToString(mType) << std::endl;
return ss.str();
}
const char* EmailOptIn::typeToString(EmailOptInType type)
{
switch (type) {
case EMAIL_OPT_IN_REGISTER: return "register";
case EMAIL_OPT_IN_RESET_PASSWORD: return "resetPassword";
default: return "<unknown>";
}
}
}
}

View File

@ -8,19 +8,28 @@
namespace model {
namespace table {
enum EmailOptInType {
EMAIL_OPT_IN_REGISTER = 1,
EMAIL_OPT_IN_RESET_PASSWORD = 2
};
class EmailOptIn : public ModelBase
{
public:
EmailOptIn(const Poco::UInt64& code, int user_id);
EmailOptIn(const Poco::UInt64& code);
EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type);
EmailOptIn(const Poco::UInt64& code, EmailOptInType type);
EmailOptIn();
~EmailOptIn();
// generic db operations
const char* getTableName() { return "email_opt_in"; }
std::string toString();
inline Poco::UInt64 getCode() const { return mEmailVerificationCode; }
inline void setCode(Poco::UInt64 code) { mEmailVerificationCode = code; }
static const char* typeToString(EmailOptInType type);
protected:
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
Poco::Data::Statement _insertIntoDB(Poco::Data::Session session);
@ -28,6 +37,8 @@ namespace model {
// data type must be a multiple of 4
Poco::UInt64 mEmailVerificationCode;
int mUserId;
EmailOptInType mType;
};
}

View File

@ -10,8 +10,8 @@
namespace model {
namespace table {
ModelInsertTask::ModelInsertTask(Poco::AutoPtr<ModelBase> model)
: UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model)
ModelInsertTask::ModelInsertTask(Poco::AutoPtr<ModelBase> model, bool emailErrors /* = false */)
: UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mEmailErrors(emailErrors)
{
#ifdef _UNI_LIB_DEBUG
setName(model->getTableName());
@ -21,8 +21,12 @@ namespace model {
int ModelInsertTask::run()
{
mModel->insertIntoDB();
return 0;
auto result = mModel->insertIntoDB();
if (mModel->errorCount() > 0 && mEmailErrors) {
mModel->sendErrorsAsEmail();
}
return !result;
//return 0;
}
// ---------------------------------------------------------------------------------------------------
@ -41,13 +45,16 @@ namespace model {
size_t resultCount = 0;
try {
return insert.execute() == 1;
}
catch (Poco::Exception& ex) {
lock();
addError(new ParamError(getTableName(), "mysql error by insert", ex.displayText().data()));
addError(new ParamError(getTableName(), "data set: ", toString().data()));
unlock();
}
//printf("data valid: %s\n", toString().data());
return false;
}

View File

@ -22,6 +22,7 @@ namespace model {
virtual ~ModelBase();
virtual const char* getTableName() = 0;
virtual std::string toString() = 0;
template<class T> size_t updateIntoDB(const std::string& fieldName, const T& fieldValue );
template<class T> size_t loadFromDB(const std::string& fieldName, const T& fieldValue);
@ -100,13 +101,14 @@ namespace model {
class ModelInsertTask : public UniLib::controller::CPUTask
{
public:
ModelInsertTask(Poco::AutoPtr<ModelBase> model);
ModelInsertTask(Poco::AutoPtr<ModelBase> model, bool emailErrors = false);
int run();
const char* getResourceType() const { return "ModelInsertTask"; };
protected:
Poco::AutoPtr<ModelBase> mModel;
bool mEmailErrors;
};
@ -115,8 +117,8 @@ namespace model {
class ModelUpdateTask : public UniLib::controller::CPUTask
{
public:
ModelUpdateTask(Poco::AutoPtr<ModelBase> model, const std::string& fieldName, const T& fieldValue)
: UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mFieldName(fieldName), mFieldValue(fieldValue)
ModelUpdateTask(Poco::AutoPtr<ModelBase> model, const std::string& fieldName, const T& fieldValue, bool emailErrors = false)
: UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mFieldName(fieldName), mFieldValue(fieldValue), mEmailErrors(emailErrors)
{
#ifdef _UNI_LIB_DEBUG
setName(model->getTableName());
@ -124,7 +126,11 @@ namespace model {
}
int run() {
mModel->updateIntoDB(mFieldName, mFieldValue);
auto result = mModel->updateIntoDB(mFieldName, mFieldValue);
if (mModel->errorCount() > 0 && mEmailErrors) {
mModel->sendErrorsAsEmail();
}
return !(result > 0);
}
const char* getResourceType() const { return "ModelUpdateTask"; };
@ -132,6 +138,7 @@ namespace model {
Poco::AutoPtr<ModelBase> mModel;
std::string mFieldName;
T mFieldValue;
bool mEmailErrors;
};

View File

@ -2,6 +2,10 @@
#include "Poco/Data/Binding.h"
#include "sodium.h"
#include "../../SingletonManager/MemoryManager.h"
using namespace Poco::Data::Keywords;
namespace model {
@ -65,11 +69,63 @@ namespace model {
{
Poco::Data::Statement select(session);
int email_checked = 0;
select << "SELECT id, email, first_name, last_name, password, pubkey, privkey, email_checked, language from " << getTableName() << " where " << fieldName << " = ?",
into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mPasswordHashed), into(mPublicKey), into(mPrivateKey), into(email_checked), into(mLanguageKey);
into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mPasswordHashed), into(mPublicKey), into(mPrivateKey), into(mEmailChecked), into(mLanguageKey);
return select;
}
/*
std::string mEmail;
std::string mFirstName;
std::string mLastName;
Poco::UInt64 mPasswordHashed;
Poco::Nullable<Poco::Data::BLOB> mPublicKey;
Poco::Nullable<Poco::Data::BLOB> mPrivateKey;
// created: Mysql DateTime
bool mEmailChecked;
std::string mLanguageKey;
char *sodium_bin2hex(char * const hex, const size_t hex_maxlen,
const unsigned char * const bin, const size_t bin_len);
*/
std::string User::toString()
{
auto mm = MemoryManager::getInstance();
auto pubkeyHex = mm->getFreeMemory(65);
auto privkeyHex = mm->getFreeMemory(161);
//char pubkeyHex[65], privkeyHex[161];
//memset(pubkeyHex, 0, 65);
//memset(privkeyHex, 0, 161);
memset(*pubkeyHex, 0, 65);
memset(*privkeyHex, 0, 161);
std::stringstream ss;
if (!mPublicKey.isNull()) {
sodium_bin2hex(*pubkeyHex, 65, mPublicKey.value().content().data(), mPublicKey.value().content().size());
}
if (!mPrivateKey.isNull()) {
sodium_bin2hex(*privkeyHex, 161, mPrivateKey.value().content().data(), mPrivateKey.value().content().size());
}
ss << mFirstName << " " << mLastName << " <" << mEmail << ">" << std::endl;
ss << "password hash: " << mPasswordHashed << std::endl;
ss << "public key: " << (char*)*pubkeyHex << std::endl;
ss << "private key: " << (char*)*privkeyHex << std::endl;
ss << "email checked: " << mEmailChecked << std::endl;
ss << "language key: " << mLanguageKey << std::endl;
mm->releaseMemory(pubkeyHex);
mm->releaseMemory(privkeyHex);
return ss.str();
}
}
}

View File

@ -31,7 +31,7 @@ namespace model {
// generic db operations
const char* getTableName() { return "users"; }
std::string toString();
// default getter unlocked