mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
put back depracted email tasks because I don't exactly know if I broke something if I remove it completly (especially model/session.cpp)
This commit is contained in:
parent
f8d174049c
commit
363e04fbe5
@ -137,7 +137,7 @@ int Session::isActive()
|
||||
try {
|
||||
mWorkMutex.tryLock(100);
|
||||
}
|
||||
catch (Poco::TimeoutException &ex) {
|
||||
catch (Poco::TimeoutException& ex) {
|
||||
return -1;
|
||||
}
|
||||
ret = (int)mActive;
|
||||
@ -164,7 +164,7 @@ bool Session::setActive(bool active)
|
||||
try {
|
||||
mWorkMutex.tryLock(100);
|
||||
}
|
||||
catch (Poco::TimeoutException &ex) {
|
||||
catch (Poco::TimeoutException& ex) {
|
||||
return false;
|
||||
}
|
||||
mActive = active;
|
||||
@ -444,7 +444,7 @@ bool Session::ifUserExist(const std::string& email)
|
||||
into(emailChecked), into(userId), useRef(email);
|
||||
|
||||
try {
|
||||
if(select.execute() == 1) return true;
|
||||
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()));
|
||||
@ -470,7 +470,7 @@ int Session::updateEmailVerification(Poco::UInt64 emailVerificationCode)
|
||||
}
|
||||
auto email_verification_code_model = mEmailVerificationCodeObject->getModel();
|
||||
assert(email_verification_code_model);
|
||||
if(email_verification_code_model->getCode() == emailVerificationCode) {
|
||||
if (email_verification_code_model->getCode() == emailVerificationCode) {
|
||||
if (mSessionUser && mSessionUser->getDBId() == 0) {
|
||||
//addError(new Error("E-Mail Verification", "Benutzer wurde nicht richtig gespeichert, bitte wende dich an den Server-Admin"));
|
||||
em->addError(new Error(funcName, "user exist with 0 as id"));
|
||||
@ -496,7 +496,7 @@ int Session::updateEmailVerification(Poco::UInt64 emailVerificationCode)
|
||||
bool first_email_activation = false;
|
||||
auto verification_type = email_verification_code_model->getType();
|
||||
if (model::table::EMAIL_OPT_IN_REGISTER == verification_type ||
|
||||
model::table::EMAIL_OPT_IN_EMPTY == verification_type ||
|
||||
model::table::EMAIL_OPT_IN_EMPTY == verification_type ||
|
||||
model::table::EMAIL_OPT_IN_REGISTER_DIRECT == verification_type) {
|
||||
first_email_activation = true;
|
||||
}
|
||||
@ -934,7 +934,7 @@ bool Session::deleteUser()
|
||||
{
|
||||
lock("Session::deleteUser");
|
||||
bool bResult = false;
|
||||
if(mSessionUser) {
|
||||
if (mSessionUser) {
|
||||
JsonRequest phpServerRequest(ServerConfig::g_php_serverHost, 443);
|
||||
Poco::Net::NameValueCollection payload;
|
||||
payload.add("user", std::string(mSessionUser->getPublicKeyHex()));
|
||||
@ -954,7 +954,7 @@ bool Session::deleteUser()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!bResult) {
|
||||
if (!bResult) {
|
||||
addError(new Error(gettext("Benutzer"), gettext("Fehler beim Löschen des Accounts. Bitte logge dich erneut ein und versuche es nochmal.")));
|
||||
}
|
||||
unlock();
|
||||
@ -1321,4 +1321,3 @@ bool Session::generateKeys(bool savePrivkey, bool savePassphrase)
|
||||
return true;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
65
login_server/src/cpp/tasks/PrepareEmailTask.cpp
Normal file
65
login_server/src/cpp/tasks/PrepareEmailTask.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "PrepareEmailTask.h"
|
||||
#include "../lib/Profiler.h"
|
||||
#include "../ServerConfig.h"
|
||||
#include "../SingletonManager/ErrorManager.h"
|
||||
|
||||
#include "Poco/Net/SSLException.h"
|
||||
|
||||
PrepareEmailTask::PrepareEmailTask(UniLib::controller::CPUSheduler* cpuScheduler)
|
||||
: UniLib::controller::CPUTask(cpuScheduler), mMailClientSession(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PrepareEmailTask::~PrepareEmailTask()
|
||||
{
|
||||
if (mMailClientSession) {
|
||||
delete mMailClientSession;
|
||||
}
|
||||
}
|
||||
|
||||
int PrepareEmailTask::run()
|
||||
{
|
||||
if (ServerConfig::g_disableEmail) return 0;
|
||||
Profiler timeUsed;
|
||||
mMailClientSession = new Poco::Net::SecureSMTPClientSession(ServerConfig::g_EmailAccount.url, ServerConfig::g_EmailAccount.port);
|
||||
mMailClientSession->login();
|
||||
try {
|
||||
mMailClientSession->startTLS(ServerConfig::g_SSL_CLient_Context);
|
||||
mMailClientSession->login(Poco::Net::SMTPClientSession::AUTH_LOGIN, ServerConfig::g_EmailAccount.username, ServerConfig::g_EmailAccount.password);
|
||||
} catch(Poco::Net::SSLException& ex) {
|
||||
printf("[PrepareEmailTask] ssl certificate error: %s\nPlease make sure you have cacert.pem (CA/root certificates) next to binary from https://curl.haxx.se/docs/caextract.html\n", ex.displayText().data());
|
||||
return -1;
|
||||
}
|
||||
|
||||
//printf("[PrepareEmailTask] time: %s\n", timeUsed.string().data());
|
||||
/*
|
||||
session.login();
|
||||
session.startTLS(pContext);
|
||||
if (!username.empty())
|
||||
{
|
||||
session.login(SMTPClientSession::AUTH_LOGIN, username, password);
|
||||
}
|
||||
session.sendMessage(message);
|
||||
session.close();
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PrepareEmailTask::send(Poco::Net::MailMessage* message)
|
||||
{
|
||||
if (ServerConfig::g_disableEmail) return 0;
|
||||
|
||||
auto er = ErrorManager::getInstance();
|
||||
try {
|
||||
mMailClientSession->sendMessage(*message);
|
||||
mMailClientSession->close();
|
||||
}
|
||||
catch (Poco::Exception& exc) {
|
||||
er->addError(new ParamError("PrepareEmailTask::send", "error sending email", exc.displayText().data()));
|
||||
printf("[PrepareEmailTask::%s] error sending email: %s\n", __FUNCTION__, exc.displayText().data());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
25
login_server/src/cpp/tasks/PrepareEmailTask.h
Normal file
25
login_server/src/cpp/tasks/PrepareEmailTask.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef GRADIDO_LOGIN_SERVER_TASKS_PREPAIRE_EMAIL_TASK_INCLUDE
|
||||
#define GRADIDO_LOGIN_SERVER_TASKS_PREPAIRE_EMAIL_TASK_INCLUDE
|
||||
|
||||
#include "CPUTask.h"
|
||||
#include "Poco/Net/SecureSMTPClientSession.h"
|
||||
|
||||
|
||||
|
||||
class PrepareEmailTask : public UniLib::controller::CPUTask
|
||||
{
|
||||
public:
|
||||
PrepareEmailTask(UniLib::controller::CPUSheduler* cpuScheduler);
|
||||
virtual ~PrepareEmailTask();
|
||||
|
||||
virtual int run();
|
||||
int send(Poco::Net::MailMessage* message);
|
||||
virtual const char* getResourceType() const { return "PrepareEmailTask"; };
|
||||
protected:
|
||||
|
||||
private:
|
||||
Poco::Net::SecureSMTPClientSession* mMailClientSession;
|
||||
};
|
||||
|
||||
|
||||
#endif //GRADIDO_LOGIN_SERVER_TASKS_PREPAIRE_EMAIL_TASK_INCLUDE
|
||||
64
login_server/src/cpp/tasks/SendEmailTask.cpp
Normal file
64
login_server/src/cpp/tasks/SendEmailTask.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include "SendEmailTask.h"
|
||||
#include "PrepareEmailTask.h"
|
||||
#include "../lib/Profiler.h"
|
||||
#include "../SingletonManager/ErrorManager.h"
|
||||
#include "../SingletonManager/EmailManager.h"
|
||||
#include "../ServerConfig.h"
|
||||
|
||||
#include "Poco/Net/MediaType.h"
|
||||
|
||||
SendEmailTask::SendEmailTask(Poco::Net::MailMessage* mailMessage, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount/* = 0*/)
|
||||
: UniLib::controller::CPUTask(cpuScheduler, additionalTaskDependenceCount+1), mMailMessage(mailMessage), mEmail(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
SendEmailTask::SendEmailTask(model::Email*email, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount/* = 0*/)
|
||||
: UniLib::controller::CPUTask(cpuScheduler, additionalTaskDependenceCount), mMailMessage(nullptr), mEmail(email)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SendEmailTask::~SendEmailTask()
|
||||
{
|
||||
if (mMailMessage) {
|
||||
delete mMailMessage;
|
||||
mMailMessage = nullptr;
|
||||
}
|
||||
if (mEmail) {
|
||||
delete mEmail;
|
||||
mEmail = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int SendEmailTask::run()
|
||||
{
|
||||
if(ServerConfig::g_disableEmail) return 0;
|
||||
|
||||
Profiler timeUsed;
|
||||
auto er = ErrorManager::getInstance();
|
||||
auto parent = getParent(0);
|
||||
|
||||
if (mMailMessage) {
|
||||
|
||||
if (strcmp(parent->getResourceType(), "PrepareEmailTask") != 0) {
|
||||
er->addError(new Error("SendEmailTask", "first parent isn't PrepareEmailTask"));
|
||||
er->sendErrorsAsEmail();
|
||||
return -1;
|
||||
}
|
||||
PrepareEmailTask* prepare = (PrepareEmailTask*)&(*parent);
|
||||
mMailMessage->setSender(ServerConfig::g_EmailAccount.sender);
|
||||
|
||||
if (prepare->send(mMailMessage)) {
|
||||
er->sendErrorsAsEmail();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (mEmail) {
|
||||
auto em = EmailManager::getInstance();
|
||||
em->addEmail(mEmail);
|
||||
mEmail = nullptr;
|
||||
}
|
||||
//printf("[SendEmailTask] time: %s\n", timeUsed.string().data());
|
||||
return 0;
|
||||
}
|
||||
36
login_server/src/cpp/tasks/SendEmailTask.h
Normal file
36
login_server/src/cpp/tasks/SendEmailTask.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE
|
||||
#define GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE
|
||||
|
||||
#include "CPUTask.h"
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
|
||||
#include "../model/email/Email.h"
|
||||
|
||||
/*
|
||||
* @author: Dario Rekowski
|
||||
*
|
||||
* @date: 29.09.19
|
||||
* @desc: Task for send an email, the first parent dependence pointer must be a prepare email task
|
||||
*/
|
||||
|
||||
|
||||
class SendEmailTask : public UniLib::controller::CPUTask
|
||||
{
|
||||
public:
|
||||
|
||||
SendEmailTask(Poco::Net::MailMessage* mailMessage, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount = 0);
|
||||
SendEmailTask(model::Email* email, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount = 0);
|
||||
virtual ~SendEmailTask();
|
||||
|
||||
virtual int run();
|
||||
|
||||
virtual const char* getResourceType() const { return "SendEmailTask"; };
|
||||
protected:
|
||||
|
||||
private:
|
||||
Poco::Net::MailMessage* mMailMessage;
|
||||
model::Email* mEmail;
|
||||
};
|
||||
|
||||
|
||||
#endif //GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE
|
||||
Loading…
x
Reference in New Issue
Block a user