mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add option for login after register via ajax
This commit is contained in:
parent
e2c38c1a0f
commit
fa999cde6f
@ -15,6 +15,7 @@ Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params)
|
|||||||
std::string first_name;
|
std::string first_name;
|
||||||
std::string last_name;
|
std::string last_name;
|
||||||
std::string password;
|
std::string password;
|
||||||
|
bool login_after_register = false;
|
||||||
int emailType;
|
int emailType;
|
||||||
auto em = EmailManager::getInstance();
|
auto em = EmailManager::getInstance();
|
||||||
auto sm = SessionManager::getInstance();
|
auto sm = SessionManager::getInstance();
|
||||||
@ -32,9 +33,13 @@ Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params)
|
|||||||
paramJsonObject->get("first_name").convert(first_name);
|
paramJsonObject->get("first_name").convert(first_name);
|
||||||
paramJsonObject->get("last_name").convert(last_name);
|
paramJsonObject->get("last_name").convert(last_name);
|
||||||
paramJsonObject->get("emailType").convert(emailType);
|
paramJsonObject->get("emailType").convert(emailType);
|
||||||
|
|
||||||
if ((ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
|
if ((ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
|
||||||
paramJsonObject->get("password").convert(password);
|
paramJsonObject->get("password").convert(password);
|
||||||
}
|
}
|
||||||
|
if (!paramJsonObject->isNull("login_after_register")) {
|
||||||
|
paramJsonObject->get("login_after_register").convert(login_after_register);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Poco::Exception& ex) {
|
catch (Poco::Exception& ex) {
|
||||||
return stateError("json exception", ex.displayText());
|
return stateError("json exception", ex.displayText());
|
||||||
@ -71,7 +76,6 @@ Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params)
|
|||||||
userModel->sendErrorsAsEmail();
|
userModel->sendErrorsAsEmail();
|
||||||
return stateError("insert user failed");
|
return stateError("insert user failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password.size()) {
|
if (password.size()) {
|
||||||
session = sm->getNewSession();
|
session = sm->getNewSession();
|
||||||
session->setUser(user);
|
session->setUser(user);
|
||||||
@ -92,6 +96,13 @@ Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params)
|
|||||||
|
|
||||||
em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType)));
|
em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType)));
|
||||||
|
|
||||||
|
if (login_after_register && session) {
|
||||||
|
Poco::JSON::Object* result = stateSuccess();
|
||||||
|
|
||||||
|
result->set("session_id", session->getHandle());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return stateSuccess();
|
return stateSuccess();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -11,6 +11,8 @@
|
|||||||
#include "../ServerConfig.h"
|
#include "../ServerConfig.h"
|
||||||
|
|
||||||
#include "../lib/DataTypeConverter.h"
|
#include "../lib/DataTypeConverter.h"
|
||||||
|
#include "../SingletonManager/SessionManager.h"
|
||||||
|
|
||||||
|
|
||||||
void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
||||||
{
|
{
|
||||||
@ -50,6 +52,21 @@ void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Po
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (json_result) {
|
if (json_result) {
|
||||||
|
if (!json_result->isNull("session_id")) {
|
||||||
|
int session_id = 0;
|
||||||
|
try {
|
||||||
|
json_result->get("session_id").convert(session_id);
|
||||||
|
}
|
||||||
|
catch (Poco::Exception& e) {
|
||||||
|
ErrorList erros;
|
||||||
|
erros.addError(new Error("json request", "invalid session_id"));
|
||||||
|
erros.sendErrorsAsEmail();
|
||||||
|
}
|
||||||
|
if (session_id) {
|
||||||
|
auto session = SessionManager::getInstance()->getSession(session_id);
|
||||||
|
response.addCookie(session->getLoginCookie());
|
||||||
|
}
|
||||||
|
}
|
||||||
json_result->stringify(responseStream);
|
json_result->stringify(responseStream);
|
||||||
delete json_result;
|
delete json_result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,40 +1,40 @@
|
|||||||
#include "AuthenticatedEncryptionCreateKeyTask.h"
|
#include "AuthenticatedEncryptionCreateKeyTask.h"
|
||||||
|
|
||||||
#include "../ServerConfig.h"
|
#include "../ServerConfig.h"
|
||||||
#include "../SingletonManager/SingletonTaskObserver.h"
|
#include "../SingletonManager/SingletonTaskObserver.h"
|
||||||
#include "../SingletonManager/ErrorManager.h"
|
#include "../SingletonManager/ErrorManager.h"
|
||||||
|
|
||||||
#include "../lib/Profiler.h"
|
#include "../lib/Profiler.h"
|
||||||
|
|
||||||
AuthenticatedEncryptionCreateKeyTask::AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr<controller::User> user, const std::string& passwd)
|
AuthenticatedEncryptionCreateKeyTask::AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr<controller::User> user, const std::string& passwd)
|
||||||
: UniLib::controller::CPUTask(ServerConfig::g_CryptoCPUScheduler), mUser(user), mPassword(passwd)
|
: UniLib::controller::CPUTask(ServerConfig::g_CryptoCPUScheduler), mUser(user), mPassword(passwd)
|
||||||
{
|
{
|
||||||
assert(!mUser.isNull());
|
assert(!mUser.isNull());
|
||||||
SingletonTaskObserver::getInstance()->addTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
|
SingletonTaskObserver::getInstance()->addTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthenticatedEncryptionCreateKeyTask::~AuthenticatedEncryptionCreateKeyTask()
|
AuthenticatedEncryptionCreateKeyTask::~AuthenticatedEncryptionCreateKeyTask()
|
||||||
{
|
{
|
||||||
SingletonTaskObserver::getInstance()->removeTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
|
SingletonTaskObserver::getInstance()->removeTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AuthenticatedEncryptionCreateKeyTask::run()
|
int AuthenticatedEncryptionCreateKeyTask::run()
|
||||||
{
|
{
|
||||||
auto em = ErrorManager::getInstance();
|
auto em = ErrorManager::getInstance();
|
||||||
const static char* function_name = "AuthenticatedEncryptionCreateKeyTask::run";
|
const static char* function_name = "AuthenticatedEncryptionCreateKeyTask::run";
|
||||||
auto authenticated_encryption = new AuthenticatedEncryption;
|
auto authenticated_encryption = new AuthenticatedEncryption;
|
||||||
Profiler timeUsed;
|
Profiler timeUsed;
|
||||||
if (AuthenticatedEncryption::AUTH_ENCRYPT_OK != authenticated_encryption->createKey(mUser->getModel()->getEmail(), mPassword)) {
|
if (AuthenticatedEncryption::AUTH_ENCRYPT_OK != authenticated_encryption->createKey(mUser->getModel()->getEmail(), mPassword)) {
|
||||||
em->addError(new Error(function_name, "error creating key"));
|
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, "for email", mUser->getModel()->getEmail()));
|
||||||
em->addError(new ParamError(function_name, "strerror: ", strerror(errno)));
|
em->addError(new ParamError(function_name, "strerror: ", strerror(errno)));
|
||||||
em->sendErrorsAsEmail();
|
em->sendErrorsAsEmail();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printf("create password time: %s\n", timeUsed.string().data());
|
//printf("create password time: %s\n", timeUsed.string().data());
|
||||||
timeUsed.reset();
|
timeUsed.reset();
|
||||||
mUser->setNewPassword(authenticated_encryption);
|
mUser->setNewPassword(authenticated_encryption);
|
||||||
printf("set password time: %s\n", timeUsed.string().data());
|
//printf("set password time: %s\n", timeUsed.string().data());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user