mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
update cmake for using multiprocessor build with visual studio, work on reset password and new db access classes
This commit is contained in:
parent
27bf842e6c
commit
abef0b1ef1
@ -97,6 +97,10 @@ set(MYSQL_INCLUDE_DIR "dependencies/mariadb-connector-c/include")
|
|||||||
# "I:/FremdCode/C++/ssl/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)
|
else(WIN32)
|
||||||
find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build" REQUIRED)
|
find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build" REQUIRED)
|
||||||
# set vars for mariadb cmake files
|
# set vars for mariadb cmake files
|
||||||
@ -110,8 +114,13 @@ include_directories(
|
|||||||
"build/dependencies/mariadb-connector-c/include"
|
"build/dependencies/mariadb-connector-c/include"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519})
|
target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519})
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
TARGET_LINK_LIBRARIES(Gradido_LoginServer optimized ${MYSQL_LIBRARIES} Shlwapi)
|
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_compile_definitions(Gradido_LoginServer_Test PUBLIC "_TEST_BUILD")
|
||||||
|
|
||||||
target_link_libraries(Gradido_LoginServer_Test ${CONAN_LIBS} ${IROHA_ED25519})
|
target_link_libraries(Gradido_LoginServer_Test ${CONAN_LIBS} ${IROHA_ED25519})
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test optimized ${MYSQL_LIBRARIES} Shlwapi)
|
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test optimized ${MYSQL_LIBRARIES} Shlwapi)
|
||||||
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi)
|
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi)
|
||||||
|
|||||||
@ -34,7 +34,7 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
|
|||||||
Poco::Net::NameValueCollection elopageRequestData;
|
Poco::Net::NameValueCollection elopageRequestData;
|
||||||
int breakCount = 100;
|
int breakCount = 100;
|
||||||
while (stream.good() && breakCount > 0) {
|
while (stream.good() && breakCount > 0) {
|
||||||
char dummy;
|
// char dummy;
|
||||||
char keyBuffer[30]; memset(keyBuffer, 0, 30);
|
char keyBuffer[30]; memset(keyBuffer, 0, 30);
|
||||||
char valueBuffer[75]; memset(valueBuffer, 0, 75);
|
char valueBuffer[75]; memset(valueBuffer, 0, 75);
|
||||||
/*stream.get(keyBuffer, 30, '=').get(dummy)
|
/*stream.get(keyBuffer, 30, '=').get(dummy)
|
||||||
@ -195,6 +195,7 @@ int HandleElopageRequestTask::getUserIdFromDB()
|
|||||||
}
|
}
|
||||||
catch (Poco::Exception& ex) {
|
catch (Poco::Exception& ex) {
|
||||||
addError(new ParamError(__FUNCTION__, "mysql error selecting from db", ex.displayText().data()));
|
addError(new ParamError(__FUNCTION__, "mysql error selecting from db", ex.displayText().data()));
|
||||||
|
addError(new ParamError(__FUNCTION__, "email: ", mEmail.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return user_id;
|
return user_id;
|
||||||
@ -378,7 +379,9 @@ int HandleElopageRequestTask::run()
|
|||||||
addError(param_error_order_id);
|
addError(param_error_order_id);
|
||||||
sendErrorsAsEmail();
|
sendErrorsAsEmail();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
delete param_error_order_id;
|
delete param_error_order_id;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -81,12 +81,13 @@ MemoryManager::MemoryManager()
|
|||||||
mMemoryPageStacks[1] = new MemoryPageStack(64); // privkey
|
mMemoryPageStacks[1] = new MemoryPageStack(64); // privkey
|
||||||
mMemoryPageStacks[2] = new MemoryPageStack(65); // pubkey hex
|
mMemoryPageStacks[2] = new MemoryPageStack(65); // pubkey hex
|
||||||
mMemoryPageStacks[3] = new MemoryPageStack(96); // privkey encrypted
|
mMemoryPageStacks[3] = new MemoryPageStack(96); // privkey encrypted
|
||||||
|
mMemoryPageStacks[4] = new MemoryPageStack(161); // privkey hex
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryManager::~MemoryManager()
|
MemoryManager::~MemoryManager()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
delete mMemoryPageStacks[i];
|
delete mMemoryPageStacks[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,6 +99,7 @@ Poco::Int8 MemoryManager::getMemoryStackIndex(Poco::UInt16 size)
|
|||||||
case 64: return 1;
|
case 64: return 1;
|
||||||
case 65: return 2;
|
case 65: return 2;
|
||||||
case 96: return 3;
|
case 96: return 3;
|
||||||
|
case 161: return 4;
|
||||||
default: return -1;
|
default: return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -76,7 +76,7 @@ protected:
|
|||||||
Poco::Int8 getMemoryStackIndex(Poco::UInt16 size);
|
Poco::Int8 getMemoryStackIndex(Poco::UInt16 size);
|
||||||
|
|
||||||
MemoryManager();
|
MemoryManager();
|
||||||
MemoryPageStack* mMemoryPageStacks[4];
|
MemoryPageStack* mMemoryPageStacks[5];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,18 +27,18 @@ namespace controller {
|
|||||||
|
|
||||||
// --------------- static members -----------------------------
|
// --------------- 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 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);
|
auto result = new EmailVerificationCode(db);
|
||||||
return Poco::AutoPtr<EmailVerificationCode>(result);
|
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 code = createEmailVerificationCode();
|
||||||
auto db = new model::table::EmailOptIn(code);
|
auto db = new model::table::EmailOptIn(code, type);
|
||||||
auto result = new EmailVerificationCode(db);
|
auto result = new EmailVerificationCode(db);
|
||||||
return Poco::AutoPtr<EmailVerificationCode>(result);
|
return Poco::AutoPtr<EmailVerificationCode>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,8 @@ namespace controller {
|
|||||||
|
|
||||||
~EmailVerificationCode();
|
~EmailVerificationCode();
|
||||||
|
|
||||||
static Poco::AutoPtr<EmailVerificationCode> create(int user_id);
|
static Poco::AutoPtr<EmailVerificationCode> create(int user_id, model::table::EmailOptInType type = model::table::EMAIL_OPT_IN_REGISTER);
|
||||||
static Poco::AutoPtr<EmailVerificationCode> create();
|
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>(); }
|
inline Poco::AutoPtr<model::table::EmailOptIn> getModel() { return _getModel<model::table::EmailOptIn>(); }
|
||||||
|
|
||||||
std::string getLink();
|
std::string getLink();
|
||||||
|
|||||||
@ -15,8 +15,8 @@ namespace controller {
|
|||||||
static Poco::AutoPtr<User> create();
|
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");
|
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 size_t 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(int user_id) { return getModel()->loadFromDB("id", user_id); }
|
||||||
int load(const unsigned char* pubkey_array);
|
int load(const unsigned char* pubkey_array);
|
||||||
|
|
||||||
inline Poco::AutoPtr<model::table::User> getModel() { return _getModel<model::table::User>(); }
|
inline Poco::AutoPtr<model::table::User> getModel() { return _getModel<model::table::User>(); }
|
||||||
|
|||||||
@ -48,6 +48,12 @@ Gradido Login Server\
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Email::Email(AutoPtr<controller::User> user, EmailType type)
|
||||||
|
: mUser(user), mType(type)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Email::~Email()
|
Email::~Email()
|
||||||
{
|
{
|
||||||
while (mAdditionalStringPartSrcs.size() > 0) {
|
while (mAdditionalStringPartSrcs.size() > 0) {
|
||||||
|
|||||||
@ -35,6 +35,7 @@ namespace model {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Email(AutoPtr<controller::EmailVerificationCode> emailVerification, AutoPtr<controller::User> user, EmailType type);
|
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
|
//! \param errors copy errors into own memory
|
||||||
Email(const std::string& errorHtml, EmailType type);
|
Email(const std::string& errorHtml, EmailType type);
|
||||||
~Email();
|
~Email();
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include "../SingletonManager/SessionManager.h"
|
#include "../SingletonManager/SessionManager.h"
|
||||||
#include "../SingletonManager/ConnectionManager.h"
|
#include "../SingletonManager/ConnectionManager.h"
|
||||||
#include "../SingletonManager/ErrorManager.h"
|
#include "../SingletonManager/ErrorManager.h"
|
||||||
|
#include "../SingletonManager/EmailManager.h"
|
||||||
|
|
||||||
#include "../tasks/PrepareEmailTask.h"
|
#include "../tasks/PrepareEmailTask.h"
|
||||||
#include "../tasks/SendEmailTask.h"
|
#include "../tasks/SendEmailTask.h"
|
||||||
@ -18,6 +19,8 @@
|
|||||||
|
|
||||||
#include "../controller/User.h"
|
#include "../controller/User.h"
|
||||||
|
|
||||||
|
#include "table/ModelBase.h"
|
||||||
|
|
||||||
|
|
||||||
#include "sodium.h"
|
#include "sodium.h"
|
||||||
|
|
||||||
@ -379,9 +382,27 @@ int Session::updateEmailVerification(Poco::UInt64 emailVerificationCode)
|
|||||||
return 0;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,7 +90,8 @@ public:
|
|||||||
//! 0 = ok
|
//! 0 = ok
|
||||||
int updateEmailVerification(Poco::UInt64 emailVerificationCode);
|
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();
|
Poco::Net::HTTPCookie getLoginCookie();
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE
|
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE
|
||||||
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE
|
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_BASE_INCLUDE
|
||||||
|
|
||||||
|
#pragma warning(disable:4800)
|
||||||
|
|
||||||
#include "../lib/ErrorList.h"
|
#include "../lib/ErrorList.h"
|
||||||
#include "../proto/gradido/BasicTypes.pb.h"
|
#include "../proto/gradido/BasicTypes.pb.h"
|
||||||
#include "../SingletonManager/MemoryManager.h"
|
#include "../SingletonManager/MemoryManager.h"
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE
|
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE
|
||||||
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE
|
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_CREATION_INCLUDE
|
||||||
|
|
||||||
|
#pragma warning(disable:4800)
|
||||||
|
|
||||||
#include "TransactionBase.h"
|
#include "TransactionBase.h"
|
||||||
#include "../proto/gradido/TransactionCreation.pb.h"
|
#include "../proto/gradido/TransactionCreation.pb.h"
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE
|
#ifndef GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE
|
||||||
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE
|
#define GRADIDO_LOGIN_SERVER_MODEL_TRANSACTION_TRANSFER_INCLUDE
|
||||||
|
|
||||||
|
#pragma warning(disable:4800)
|
||||||
|
|
||||||
#include "TransactionBase.h"
|
#include "TransactionBase.h"
|
||||||
#include "../proto/gradido/Transfer.pb.h"
|
#include "../proto/gradido/Transfer.pb.h"
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "ElopageBuy.h"
|
#include "ElopageBuy.h"
|
||||||
|
#include "Poco/DateTimeFormatter.h"
|
||||||
|
|
||||||
using namespace Poco::Data::Keywords;
|
using namespace Poco::Data::Keywords;
|
||||||
|
|
||||||
@ -67,6 +68,22 @@ namespace model {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
Poco::Data::Statement ElopageBuy::_loadFromDB(Poco::Data::Session session, const std::string& fieldName)
|
||||||
{
|
{
|
||||||
// Poco::Data::Statement select(session);
|
// Poco::Data::Statement select(session);
|
||||||
|
|||||||
@ -36,6 +36,7 @@ namespace model {
|
|||||||
// generic db operations
|
// generic db operations
|
||||||
const char* getTableName() { return "elopage_buys"; }
|
const char* getTableName() { return "elopage_buys"; }
|
||||||
|
|
||||||
|
std::string toString();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
|
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
|
||||||
|
|||||||
@ -6,14 +6,14 @@ using namespace Poco::Data::Keywords;
|
|||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
namespace table {
|
namespace table {
|
||||||
EmailOptIn::EmailOptIn(const Poco::UInt64& code, int user_id)
|
EmailOptIn::EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/)
|
||||||
: mUserId(user_id), mEmailVerificationCode(code)
|
: mUserId(user_id), mEmailVerificationCode(code), mType(type)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EmailOptIn::EmailOptIn(const Poco::UInt64& code)
|
EmailOptIn::EmailOptIn(const Poco::UInt64& code, EmailOptInType type/* = EMAIL_OPT_IN_REGISTER*/)
|
||||||
: mUserId(0), mEmailVerificationCode(code)
|
: mUserId(0), mEmailVerificationCode(code), mType(type)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -36,8 +36,8 @@ namespace model {
|
|||||||
|
|
||||||
lock();
|
lock();
|
||||||
insert << "INSERT INTO " << getTableName()
|
insert << "INSERT INTO " << getTableName()
|
||||||
<< " (user_id, verification_code) VALUES(?,?)"
|
<< " (user_id, verification_code, email_opt_in_type_id) VALUES(?,?,?))"
|
||||||
, bind(mUserId), bind(mEmailVerificationCode);
|
, bind(mUserId), bind(mEmailVerificationCode), bind(mType);
|
||||||
unlock();
|
unlock();
|
||||||
return insert;
|
return insert;
|
||||||
}
|
}
|
||||||
@ -47,12 +47,33 @@ namespace model {
|
|||||||
{
|
{
|
||||||
Poco::Data::Statement select(session);
|
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 << " = ?"
|
<< " where " << fieldName << " = ?"
|
||||||
, into(mUserId), into(mEmailVerificationCode);
|
, into(mUserId), into(mEmailVerificationCode), into(iType);
|
||||||
|
|
||||||
|
mType = static_cast<EmailOptInType>(iType);
|
||||||
|
|
||||||
return select;
|
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>";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,19 +8,28 @@
|
|||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
namespace table {
|
namespace table {
|
||||||
|
|
||||||
|
enum EmailOptInType {
|
||||||
|
EMAIL_OPT_IN_REGISTER = 1,
|
||||||
|
EMAIL_OPT_IN_RESET_PASSWORD = 2
|
||||||
|
};
|
||||||
|
|
||||||
class EmailOptIn : public ModelBase
|
class EmailOptIn : public ModelBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EmailOptIn(const Poco::UInt64& code, int user_id);
|
EmailOptIn(const Poco::UInt64& code, int user_id, EmailOptInType type);
|
||||||
EmailOptIn(const Poco::UInt64& code);
|
EmailOptIn(const Poco::UInt64& code, EmailOptInType type);
|
||||||
EmailOptIn();
|
EmailOptIn();
|
||||||
~EmailOptIn();
|
~EmailOptIn();
|
||||||
|
|
||||||
// generic db operations
|
// generic db operations
|
||||||
const char* getTableName() { return "email_opt_in"; }
|
const char* getTableName() { return "email_opt_in"; }
|
||||||
|
std::string toString();
|
||||||
|
|
||||||
inline Poco::UInt64 getCode() const { return mEmailVerificationCode; }
|
inline Poco::UInt64 getCode() const { return mEmailVerificationCode; }
|
||||||
inline void setCode(Poco::UInt64 code) { mEmailVerificationCode = code; }
|
inline void setCode(Poco::UInt64 code) { mEmailVerificationCode = code; }
|
||||||
|
|
||||||
|
static const char* typeToString(EmailOptInType type);
|
||||||
protected:
|
protected:
|
||||||
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
|
Poco::Data::Statement _loadFromDB(Poco::Data::Session session, const std::string& fieldName);
|
||||||
Poco::Data::Statement _insertIntoDB(Poco::Data::Session session);
|
Poco::Data::Statement _insertIntoDB(Poco::Data::Session session);
|
||||||
@ -28,6 +37,8 @@ namespace model {
|
|||||||
// data type must be a multiple of 4
|
// data type must be a multiple of 4
|
||||||
Poco::UInt64 mEmailVerificationCode;
|
Poco::UInt64 mEmailVerificationCode;
|
||||||
int mUserId;
|
int mUserId;
|
||||||
|
EmailOptInType mType;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,8 @@
|
|||||||
namespace model {
|
namespace model {
|
||||||
namespace table {
|
namespace table {
|
||||||
|
|
||||||
ModelInsertTask::ModelInsertTask(Poco::AutoPtr<ModelBase> model)
|
ModelInsertTask::ModelInsertTask(Poco::AutoPtr<ModelBase> model, bool emailErrors /* = false */)
|
||||||
: UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model)
|
: UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mEmailErrors(emailErrors)
|
||||||
{
|
{
|
||||||
#ifdef _UNI_LIB_DEBUG
|
#ifdef _UNI_LIB_DEBUG
|
||||||
setName(model->getTableName());
|
setName(model->getTableName());
|
||||||
@ -21,8 +21,12 @@ namespace model {
|
|||||||
|
|
||||||
int ModelInsertTask::run()
|
int ModelInsertTask::run()
|
||||||
{
|
{
|
||||||
mModel->insertIntoDB();
|
auto result = mModel->insertIntoDB();
|
||||||
return 0;
|
if (mModel->errorCount() > 0 && mEmailErrors) {
|
||||||
|
mModel->sendErrorsAsEmail();
|
||||||
|
}
|
||||||
|
return !result;
|
||||||
|
//return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------
|
||||||
@ -41,13 +45,16 @@ namespace model {
|
|||||||
|
|
||||||
size_t resultCount = 0;
|
size_t resultCount = 0;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return insert.execute() == 1;
|
return insert.execute() == 1;
|
||||||
}
|
}
|
||||||
catch (Poco::Exception& ex) {
|
catch (Poco::Exception& ex) {
|
||||||
lock();
|
lock();
|
||||||
addError(new ParamError(getTableName(), "mysql error by insert", ex.displayText().data()));
|
addError(new ParamError(getTableName(), "mysql error by insert", ex.displayText().data()));
|
||||||
|
addError(new ParamError(getTableName(), "data set: ", toString().data()));
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
//printf("data valid: %s\n", toString().data());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@ namespace model {
|
|||||||
virtual ~ModelBase();
|
virtual ~ModelBase();
|
||||||
|
|
||||||
virtual const char* getTableName() = 0;
|
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 updateIntoDB(const std::string& fieldName, const T& fieldValue );
|
||||||
template<class T> size_t loadFromDB(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
|
class ModelInsertTask : public UniLib::controller::CPUTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ModelInsertTask(Poco::AutoPtr<ModelBase> model);
|
ModelInsertTask(Poco::AutoPtr<ModelBase> model, bool emailErrors = false);
|
||||||
|
|
||||||
int run();
|
int run();
|
||||||
const char* getResourceType() const { return "ModelInsertTask"; };
|
const char* getResourceType() const { return "ModelInsertTask"; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Poco::AutoPtr<ModelBase> mModel;
|
Poco::AutoPtr<ModelBase> mModel;
|
||||||
|
bool mEmailErrors;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,8 +117,8 @@ namespace model {
|
|||||||
class ModelUpdateTask : public UniLib::controller::CPUTask
|
class ModelUpdateTask : public UniLib::controller::CPUTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ModelUpdateTask(Poco::AutoPtr<ModelBase> model, const std::string& fieldName, const T& 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)
|
: UniLib::controller::CPUTask(ServerConfig::g_CPUScheduler), mModel(model), mFieldName(fieldName), mFieldValue(fieldValue), mEmailErrors(emailErrors)
|
||||||
{
|
{
|
||||||
#ifdef _UNI_LIB_DEBUG
|
#ifdef _UNI_LIB_DEBUG
|
||||||
setName(model->getTableName());
|
setName(model->getTableName());
|
||||||
@ -124,7 +126,11 @@ namespace model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int run() {
|
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"; };
|
const char* getResourceType() const { return "ModelUpdateTask"; };
|
||||||
|
|
||||||
@ -132,6 +138,7 @@ namespace model {
|
|||||||
Poco::AutoPtr<ModelBase> mModel;
|
Poco::AutoPtr<ModelBase> mModel;
|
||||||
std::string mFieldName;
|
std::string mFieldName;
|
||||||
T mFieldValue;
|
T mFieldValue;
|
||||||
|
bool mEmailErrors;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
#include "Poco/Data/Binding.h"
|
#include "Poco/Data/Binding.h"
|
||||||
|
|
||||||
|
#include "sodium.h"
|
||||||
|
|
||||||
|
#include "../../SingletonManager/MemoryManager.h"
|
||||||
|
|
||||||
using namespace Poco::Data::Keywords;
|
using namespace Poco::Data::Keywords;
|
||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
@ -65,11 +69,63 @@ namespace model {
|
|||||||
{
|
{
|
||||||
|
|
||||||
Poco::Data::Statement select(session);
|
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 << " = ?",
|
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;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ namespace model {
|
|||||||
|
|
||||||
// generic db operations
|
// generic db operations
|
||||||
const char* getTableName() { return "users"; }
|
const char* getTableName() { return "users"; }
|
||||||
|
std::string toString();
|
||||||
|
|
||||||
|
|
||||||
// default getter unlocked
|
// default getter unlocked
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user