mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add AuthenticatedEncryptionCreateKeyTask for running password creation in background
This commit is contained in:
parent
8170bb21f0
commit
b285768fce
33
src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.cpp
Normal file
33
src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.cpp
Normal 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;
|
||||
}
|
||||
20
src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.h
Normal file
20
src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.h
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user