mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix errors
This commit is contained in:
parent
28900e04fe
commit
7b0828d22d
@ -2,12 +2,20 @@
|
|||||||
#include "Poco/URI.h"
|
#include "Poco/URI.h"
|
||||||
|
|
||||||
#include "../SingletonManager/SessionManager.h"
|
#include "../SingletonManager/SessionManager.h"
|
||||||
|
#include "../SingletonManager/SingletonTaskObserver.h"
|
||||||
|
#include "../SingletonManager/ErrorManager.h"
|
||||||
|
|
||||||
Poco::JSON::Object* JsonGetLogin::handle(Poco::Dynamic::Var params)
|
Poco::JSON::Object* JsonGetLogin::handle(Poco::Dynamic::Var params)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int session_id = 0;
|
int session_id = 0;
|
||||||
Poco::JSON::Object* result = new Poco::JSON::Object;
|
Poco::JSON::Object* result = new Poco::JSON::Object;
|
||||||
|
/*result->set("state", "debugging");
|
||||||
|
result->set("msg", "deactivate for debugging");
|
||||||
|
return result;
|
||||||
|
*/
|
||||||
|
|
||||||
if (params.isStruct()) {
|
if (params.isStruct()) {
|
||||||
session_id = params["session_id"];
|
session_id = params["session_id"];
|
||||||
//std::string miau = params["miau"];
|
//std::string miau = params["miau"];
|
||||||
@ -52,18 +60,43 @@ Poco::JSON::Object* JsonGetLogin::handle(Poco::Dynamic::Var params)
|
|||||||
|
|
||||||
if (session_id) {
|
if (session_id) {
|
||||||
auto sm = SessionManager::getInstance();
|
auto sm = SessionManager::getInstance();
|
||||||
|
auto observer = SingletonTaskObserver::getInstance();
|
||||||
auto session = sm->getSession(session_id);
|
auto session = sm->getSession(session_id);
|
||||||
if (session) {
|
if (session) {
|
||||||
|
auto userNew = session->getNewUser();
|
||||||
auto user = session->getUser();
|
auto user = session->getUser();
|
||||||
if (!user) {
|
if (user.isNull()) {
|
||||||
result->set("state", "not found");
|
result->set("state", "not found");
|
||||||
result->set("msg", "Session didn't contain user");
|
result->set("msg", "Session didn't contain user");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
auto userModel = userNew->getModel();
|
||||||
|
if(userModel.isNull()) {
|
||||||
|
result->set("state", "not found");
|
||||||
|
result->set("msg", "user is empty");
|
||||||
|
return result;
|
||||||
|
}//*/
|
||||||
result->set("state", "success");
|
result->set("state", "success");
|
||||||
result->set("clientIP", session->getClientIp().toString());
|
result->set("clientIP", session->getClientIp().toString());
|
||||||
result->set("user", user->getJson());
|
try {
|
||||||
|
result->set("user", userNew->getJson());
|
||||||
|
}
|
||||||
|
catch (Poco::Exception ex) {
|
||||||
|
auto em = ErrorManager::getInstance();
|
||||||
|
em->addError(new ParamError("JsonGetLogin::handle", "poco exception calling userModel->getJson: ", ex.displayText().data()));
|
||||||
|
em->sendErrorsAsEmail();
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
auto em = ErrorManager::getInstance();
|
||||||
|
em->addError(new Error("JsonGetLogin::handle", "generic exception calling userModel->getJson: "));
|
||||||
|
em->sendErrorsAsEmail();
|
||||||
|
}
|
||||||
result->set("Transaction.pending", session->getProcessingTransactionCount());
|
result->set("Transaction.pending", session->getProcessingTransactionCount());
|
||||||
|
auto executing = observer->getTaskCount(userModel->getEmail(), TASK_OBSERVER_SIGN_TRANSACTION);
|
||||||
|
if (executing < 0) {
|
||||||
|
executing = 0;
|
||||||
|
}
|
||||||
|
result->set("Transaction.executing", executing);
|
||||||
//printf("pending: %d\n", session->getProcessingTransactionCount());
|
//printf("pending: %d\n", session->getProcessingTransactionCount());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -443,7 +443,7 @@ void SessionManager::deleteLoginCookies(Poco::Net::HTTPServerRequest& request, P
|
|||||||
// max age of 0 delete cookie
|
// max age of 0 delete cookie
|
||||||
keks.setMaxAge(0);
|
keks.setMaxAge(0);
|
||||||
response.addCookie(keks);
|
response.addCookie(keks);
|
||||||
printf("remove PHP Kekse\n");
|
//printf("remove PHP Kekse\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
#include "User.h"
|
#include "User.h"
|
||||||
|
|
||||||
|
#include "sodium.h"
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
User::User(model::table::User* dbModel)
|
User::User(model::table::User* dbModel)
|
||||||
: mUserRole(USER_ROLE_NOT_LOADED)
|
|
||||||
{
|
{
|
||||||
mDBModel = dbModel;
|
mDBModel = dbModel;
|
||||||
}
|
}
|
||||||
@ -33,4 +34,38 @@ namespace controller {
|
|||||||
return getModel()->loadFromDB("pubkey", pubkey);
|
return getModel()->loadFromDB("pubkey", pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& User::getPublicHex()
|
||||||
|
{
|
||||||
|
if (mPublicHex != "") {
|
||||||
|
return mPublicHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto mm = MemoryManager::getInstance();
|
||||||
|
auto pubkeyHex = mm->getFreeMemory(65);
|
||||||
|
memset(*pubkeyHex, 0, 65);
|
||||||
|
|
||||||
|
lock("User::getJson");
|
||||||
|
Poco::JSON::Object userObj;
|
||||||
|
|
||||||
|
auto pubkey = getModel()->getPublicKey();
|
||||||
|
|
||||||
|
if (pubkey) {
|
||||||
|
sodium_bin2hex(*pubkeyHex, 65, pubkey, 32);
|
||||||
|
}
|
||||||
|
mPublicHex = (char*)*pubkeyHex;
|
||||||
|
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
mm->releaseMemory(pubkeyHex);
|
||||||
|
|
||||||
|
return mPublicHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
Poco::JSON::Object User::getJson()
|
||||||
|
{
|
||||||
|
auto json = getModel()->getJson();
|
||||||
|
json.set("public_hex", getPublicHex());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -29,15 +29,19 @@ namespace controller {
|
|||||||
inline size_t load(const std::string& email) { return getModel()->loadFromDB("email", email); }
|
inline size_t load(const std::string& email) { return getModel()->loadFromDB("email", email); }
|
||||||
inline size_t 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);
|
||||||
|
Poco::JSON::Object getJson();
|
||||||
|
|
||||||
inline Poco::AutoPtr<model::table::User> getModel() { return _getModel<model::table::User>(); }
|
inline Poco::AutoPtr<model::table::User> getModel() { return _getModel<model::table::User>(); }
|
||||||
inline const model::table::User* getModel() const { return _getModel<model::table::User>(); }
|
inline const model::table::User* getModel() const { return _getModel<model::table::User>(); }
|
||||||
|
|
||||||
|
const std::string& getPublicHex();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
User(model::table::User* dbModel);
|
User(model::table::User* dbModel);
|
||||||
UserLoadedRole mUserRole;
|
|
||||||
|
std::string mPublicHex;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -419,6 +419,11 @@ User::User(Poco::AutoPtr<controller::User> ctrl_user)
|
|||||||
mEmailChecked = model->isEmailChecked();
|
mEmailChecked = model->isEmailChecked();
|
||||||
mLanguage = LanguageManager::languageFromString(model->getLanguageKey());
|
mLanguage = LanguageManager::languageFromString(model->getLanguageKey());
|
||||||
mLanguageCatalog = LanguageManager::getInstance()->getFreeCatalog(mLanguage);
|
mLanguageCatalog = LanguageManager::getInstance()->getFreeCatalog(mLanguage);
|
||||||
|
|
||||||
|
mState = USER_LOADED_FROM_DB;
|
||||||
|
if (!mEmailChecked) { mState = USER_EMAIL_NOT_ACTIVATED; }
|
||||||
|
else if (!mPrivateKey) { mState = USER_NO_PRIVATE_KEY; }
|
||||||
|
else { mState = USER_COMPLETE; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -67,12 +67,15 @@ namespace model {
|
|||||||
|
|
||||||
Poco::Data::Statement User::_loadFromDB(Poco::Data::Session session, const std::string& fieldName)
|
Poco::Data::Statement User::_loadFromDB(Poco::Data::Session session, const std::string& fieldName)
|
||||||
{
|
{
|
||||||
|
std::string _fieldName = fieldName;
|
||||||
|
if (_fieldName == "id") {
|
||||||
|
_fieldName = getTableName() + std::string(".id");
|
||||||
|
}
|
||||||
Poco::Data::Statement select(session);
|
Poco::Data::Statement select(session);
|
||||||
select << "SELECT id, email, first_name, last_name, password, pubkey, privkey, email_checked, language, user_roles.role_id "
|
select << "SELECT " << getTableName() << ".id, email, first_name, last_name, password, pubkey, privkey, email_checked, language, user_roles.role_id "
|
||||||
<< " FROM " << getTableName()
|
<< " FROM " << getTableName()
|
||||||
<< " LEFT JOIN user_roles ON " << getTableName() << ".id = user_roles.user_id "
|
<< " LEFT JOIN user_roles ON " << getTableName() << ".id = user_roles.user_id "
|
||||||
<< " WHERE " << fieldName << " = ?"
|
<< " WHERE " << _fieldName << " = ?"
|
||||||
,into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mPasswordHashed), into(mPublicKey), into(mPrivateKey), into(mEmailChecked), into(mLanguageKey), into(mRole);
|
,into(mID), into(mEmail), into(mFirstName), into(mLastName), into(mPasswordHashed), into(mPublicKey), into(mPrivateKey), into(mEmailChecked), into(mLanguageKey), into(mRole);
|
||||||
|
|
||||||
|
|
||||||
@ -144,29 +147,26 @@ namespace model {
|
|||||||
|
|
||||||
Poco::JSON::Object User::getJson()
|
Poco::JSON::Object User::getJson()
|
||||||
{
|
{
|
||||||
auto mm = MemoryManager::getInstance();
|
|
||||||
auto pubkeyHex = mm->getFreeMemory(65);
|
|
||||||
memset(*pubkeyHex, 0, 65);
|
|
||||||
|
|
||||||
lock("User::getJson");
|
lock("User::getJson");
|
||||||
Poco::JSON::Object userObj;
|
Poco::JSON::Object userObj;
|
||||||
|
|
||||||
if (!mPublicKey.isNull()) {
|
|
||||||
sodium_bin2hex(*pubkeyHex, 65, mPublicKey.value().content().data(), mPublicKey.value().content().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
userObj.set("first_name", mFirstName);
|
userObj.set("first_name", mFirstName);
|
||||||
userObj.set("last_name", mLastName);
|
userObj.set("last_name", mLastName);
|
||||||
userObj.set("email", mEmail);
|
userObj.set("email", mEmail);
|
||||||
userObj.set("public_hex", (char*)*pubkeyHex);
|
|
||||||
//userObj.set("state", userStateToString(mState));
|
//userObj.set("state", userStateToString(mState));
|
||||||
userObj.set("email_checked", mEmailChecked);
|
userObj.set("email_checked", mEmailChecked);
|
||||||
userObj.set("ident_hash", DRMakeStringHash(mEmail.data(), mEmail.size()));
|
userObj.set("ident_hash", DRMakeStringHash(mEmail.data(), mEmail.size()));
|
||||||
userObj.set("role", UserRoles::typeToString(getRole()));
|
try {
|
||||||
|
userObj.set("role", UserRoles::typeToString(getRole()));
|
||||||
|
}
|
||||||
|
catch (Poco::Exception ex) {
|
||||||
|
addError(new ParamError("User::getJson", "exception by getting role", ex.displayText().data()));
|
||||||
|
sendErrorsAsEmail();
|
||||||
|
}
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
mm->releaseMemory(pubkeyHex);
|
|
||||||
|
|
||||||
return userObj;
|
return userObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user