add AuthenticatedEncryptionCreateKeyTask for running password creation in background

This commit is contained in:
Dario 2020-06-08 13:40:21 +02:00
parent 8170bb21f0
commit b285768fce
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,33 @@
#include "AuthenticatedEncryptionCreateKeyTask.h"
#include "../ServerConfig.h"
#include "../SingletonManager/SingletonTaskObserver.h"
#include "../SingletonManager/ErrorManager.h"
AuthenticatedEncryptionCreateKeyTask::AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr<controller::User> user, const std::string& passwd)
: UniLib::controller::CPUTask(ServerConfig::g_CryptoCPUScheduler), mUser(user), mPassword(passwd)
{
SingletonTaskObserver::getInstance()->addTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
}
AuthenticatedEncryptionCreateKeyTask::~AuthenticatedEncryptionCreateKeyTask()
{
SingletonTaskObserver::getInstance()->removeTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
}
int AuthenticatedEncryptionCreateKeyTask::run()
{
auto em = ErrorManager::getInstance();
const static char* function_name = "AuthenticatedEncryptionCreateKeyTask::run";
auto authenticated_encryption = new AuthenticatedEncryption;
if (AuthenticatedEncryption::AUTH_ENCRYPT_OK != authenticated_encryption->createKey(mUser->getModel()->getEmail(), mPassword)) {
em->addError(new Error(function_name, "error creating key"));
em->addError(new ParamError(function_name, "for email", mUser->getModel()->getEmail()));
em->addError(new ParamError(function_name, "strerror: ", strerror(errno)));
em->sendErrorsAsEmail();
return -1;
}
mUser->setPassword(authenticated_encryption);
return 0;
}

View File

@ -0,0 +1,20 @@
#ifndef __GRADIDO_LOGIN_SERVER_TASKS_AUTHENTICATED_ENCRYPTION_CREATE_KEY_TASK_H
#define __GRADIDO_LOGIN_SERVER_TASKS_AUTHENTICATED_ENCRYPTION_CREATE_KEY_TASK_H
#include "CPUTask.h"
#include "../controller/User.h"
class AuthenticatedEncryptionCreateKeyTask : public UniLib::controller::CPUTask
{
public:
AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr<controller::User> user, const std::string& passwd);
virtual ~AuthenticatedEncryptionCreateKeyTask();
int run();
const char* getResourceType() const { return "AuthenticatedEncryptionCreateKeyTask"; };
protected:
Poco::AutoPtr<controller::User> mUser;
std::string mPassword;
};
#endif //__GRADIDO_LOGIN_SERVER_TASKS_AUTHENTICATED_ENCRYPTION_CREATE_KEY_TASK_H