/** * * User.cc * DO NOT EDIT. This file is generated by drogon_ctl * */ #include "User.h" #include "drogon/utils/Utilities.h" #include using namespace drogon; using namespace drogon::orm; using namespace drogon_model::sqlite3; const std::string User::Cols::_id = "id"; const std::string User::Cols::_gitlab = "gitlab"; const std::string User::Cols::_name = "name"; const std::string User::Cols::_password = "password"; const std::string User::Cols::_role = "role"; const std::string User::Cols::_root_id = "root_id"; const std::string User::Cols::_tfa_type = "tfa_type"; const std::string User::Cols::_tfa_secret = "tfa_secret"; const std::string User::Cols::_gitlab_at = "gitlab_at"; const std::string User::Cols::_gitlab_rt = "gitlab_rt"; const std::string User::primaryKeyName = "id"; const bool User::hasPrimaryKey = true; const std::string User::tableName = "user"; const std::vector User::metaData_={ {"id","uint64_t","integer",8,1,1,1}, {"gitlab","uint64_t","integer",8,0,0,1}, {"name","std::string","text",0,0,0,1}, {"password","std::string","text",0,0,0,1}, {"role","uint64_t","integer",8,0,0,1}, {"root_id","uint64_t","integer",8,0,0,1}, {"tfa_type","uint64_t","integer",8,0,0,1}, {"tfa_secret","std::vector","blob",0,0,0,0}, {"gitlab_at","std::string","text",0,0,0,0}, {"gitlab_rt","std::string","text",0,0,0,0} }; const std::string &User::getColumnName(size_t index) noexcept(false) { assert(index < metaData_.size()); return metaData_[index].colName_; } User::User(const Row &r, const ssize_t indexOffset) noexcept { if(indexOffset < 0) { if(!r["id"].isNull()) { id_=std::make_shared(r["id"].as()); } if(!r["gitlab"].isNull()) { gitlab_=std::make_shared(r["gitlab"].as()); } if(!r["name"].isNull()) { name_=std::make_shared(r["name"].as()); } if(!r["password"].isNull()) { password_=std::make_shared(r["password"].as()); } if(!r["role"].isNull()) { role_=std::make_shared(r["role"].as()); } if(!r["root_id"].isNull()) { rootId_=std::make_shared(r["root_id"].as()); } if(!r["tfa_type"].isNull()) { tfaType_=std::make_shared(r["tfa_type"].as()); } if(!r["tfa_secret"].isNull()) { tfaSecret_=std::make_shared>(r["tfa_secret"].as>()); } if(!r["gitlab_at"].isNull()) { gitlabAt_=std::make_shared(r["gitlab_at"].as()); } if(!r["gitlab_rt"].isNull()) { gitlabRt_=std::make_shared(r["gitlab_rt"].as()); } } else { size_t offset = (size_t)indexOffset; if(offset + 10 > r.size()) { LOG_FATAL << "Invalid SQL result for this model"; return; } size_t index; index = offset + 0; if(!r[index].isNull()) { id_=std::make_shared(r[index].as()); } index = offset + 1; if(!r[index].isNull()) { gitlab_=std::make_shared(r[index].as()); } index = offset + 2; if(!r[index].isNull()) { name_=std::make_shared(r[index].as()); } index = offset + 3; if(!r[index].isNull()) { password_=std::make_shared(r[index].as()); } index = offset + 4; if(!r[index].isNull()) { role_=std::make_shared(r[index].as()); } index = offset + 5; if(!r[index].isNull()) { rootId_=std::make_shared(r[index].as()); } index = offset + 6; if(!r[index].isNull()) { tfaType_=std::make_shared(r[index].as()); } index = offset + 7; if(!r[index].isNull()) { tfaSecret_=std::make_shared>(r[index].as>()); } index = offset + 8; if(!r[index].isNull()) { gitlabAt_=std::make_shared(r[index].as()); } index = offset + 9; if(!r[index].isNull()) { gitlabRt_=std::make_shared(r[index].as()); } } } User::User(const Json::Value &pJson, const std::vector &pMasqueradingVector) noexcept(false) { if(pMasqueradingVector.size() != 10) { LOG_ERROR << "Bad masquerading vector"; return; } if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0])) { dirtyFlag_[0] = true; if(!pJson[pMasqueradingVector[0]].isNull()) { id_=std::make_shared((uint64_t)pJson[pMasqueradingVector[0]].asUInt64()); } } if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1])) { dirtyFlag_[1] = true; if(!pJson[pMasqueradingVector[1]].isNull()) { gitlab_=std::make_shared((uint64_t)pJson[pMasqueradingVector[1]].asUInt64()); } } if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2])) { dirtyFlag_[2] = true; if(!pJson[pMasqueradingVector[2]].isNull()) { name_=std::make_shared(pJson[pMasqueradingVector[2]].asString()); } } if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3])) { dirtyFlag_[3] = true; if(!pJson[pMasqueradingVector[3]].isNull()) { password_=std::make_shared(pJson[pMasqueradingVector[3]].asString()); } } if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4])) { dirtyFlag_[4] = true; if(!pJson[pMasqueradingVector[4]].isNull()) { role_=std::make_shared((uint64_t)pJson[pMasqueradingVector[4]].asUInt64()); } } if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5])) { dirtyFlag_[5] = true; if(!pJson[pMasqueradingVector[5]].isNull()) { rootId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[5]].asUInt64()); } } if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6])) { dirtyFlag_[6] = true; if(!pJson[pMasqueradingVector[6]].isNull()) { tfaType_=std::make_shared((uint64_t)pJson[pMasqueradingVector[6]].asUInt64()); } } if(!pMasqueradingVector[7].empty() && pJson.isMember(pMasqueradingVector[7])) { dirtyFlag_[7] = true; if(!pJson[pMasqueradingVector[7]].isNull()) { auto str = pJson[pMasqueradingVector[7]].asString(); tfaSecret_=std::make_shared>(drogon::utils::base64DecodeToVector(str)); } } if(!pMasqueradingVector[8].empty() && pJson.isMember(pMasqueradingVector[8])) { dirtyFlag_[8] = true; if(!pJson[pMasqueradingVector[8]].isNull()) { gitlabAt_=std::make_shared(pJson[pMasqueradingVector[8]].asString()); } } if(!pMasqueradingVector[9].empty() && pJson.isMember(pMasqueradingVector[9])) { dirtyFlag_[9] = true; if(!pJson[pMasqueradingVector[9]].isNull()) { gitlabRt_=std::make_shared(pJson[pMasqueradingVector[9]].asString()); } } } User::User(const Json::Value &pJson) noexcept(false) { if(pJson.isMember("id")) { dirtyFlag_[0]=true; if(!pJson["id"].isNull()) { id_=std::make_shared((uint64_t)pJson["id"].asUInt64()); } } if(pJson.isMember("gitlab")) { dirtyFlag_[1]=true; if(!pJson["gitlab"].isNull()) { gitlab_=std::make_shared((uint64_t)pJson["gitlab"].asUInt64()); } } if(pJson.isMember("name")) { dirtyFlag_[2]=true; if(!pJson["name"].isNull()) { name_=std::make_shared(pJson["name"].asString()); } } if(pJson.isMember("password")) { dirtyFlag_[3]=true; if(!pJson["password"].isNull()) { password_=std::make_shared(pJson["password"].asString()); } } if(pJson.isMember("role")) { dirtyFlag_[4]=true; if(!pJson["role"].isNull()) { role_=std::make_shared((uint64_t)pJson["role"].asUInt64()); } } if(pJson.isMember("root_id")) { dirtyFlag_[5]=true; if(!pJson["root_id"].isNull()) { rootId_=std::make_shared((uint64_t)pJson["root_id"].asUInt64()); } } if(pJson.isMember("tfa_type")) { dirtyFlag_[6]=true; if(!pJson["tfa_type"].isNull()) { tfaType_=std::make_shared((uint64_t)pJson["tfa_type"].asUInt64()); } } if(pJson.isMember("tfa_secret")) { dirtyFlag_[7]=true; if(!pJson["tfa_secret"].isNull()) { auto str = pJson["tfa_secret"].asString(); tfaSecret_=std::make_shared>(drogon::utils::base64DecodeToVector(str)); } } if(pJson.isMember("gitlab_at")) { dirtyFlag_[8]=true; if(!pJson["gitlab_at"].isNull()) { gitlabAt_=std::make_shared(pJson["gitlab_at"].asString()); } } if(pJson.isMember("gitlab_rt")) { dirtyFlag_[9]=true; if(!pJson["gitlab_rt"].isNull()) { gitlabRt_=std::make_shared(pJson["gitlab_rt"].asString()); } } } void User::updateByMasqueradedJson(const Json::Value &pJson, const std::vector &pMasqueradingVector) noexcept(false) { if(pMasqueradingVector.size() != 10) { LOG_ERROR << "Bad masquerading vector"; return; } if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0])) { if(!pJson[pMasqueradingVector[0]].isNull()) { id_=std::make_shared((uint64_t)pJson[pMasqueradingVector[0]].asUInt64()); } } if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1])) { dirtyFlag_[1] = true; if(!pJson[pMasqueradingVector[1]].isNull()) { gitlab_=std::make_shared((uint64_t)pJson[pMasqueradingVector[1]].asUInt64()); } } if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2])) { dirtyFlag_[2] = true; if(!pJson[pMasqueradingVector[2]].isNull()) { name_=std::make_shared(pJson[pMasqueradingVector[2]].asString()); } } if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3])) { dirtyFlag_[3] = true; if(!pJson[pMasqueradingVector[3]].isNull()) { password_=std::make_shared(pJson[pMasqueradingVector[3]].asString()); } } if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4])) { dirtyFlag_[4] = true; if(!pJson[pMasqueradingVector[4]].isNull()) { role_=std::make_shared((uint64_t)pJson[pMasqueradingVector[4]].asUInt64()); } } if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5])) { dirtyFlag_[5] = true; if(!pJson[pMasqueradingVector[5]].isNull()) { rootId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[5]].asUInt64()); } } if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6])) { dirtyFlag_[6] = true; if(!pJson[pMasqueradingVector[6]].isNull()) { tfaType_=std::make_shared((uint64_t)pJson[pMasqueradingVector[6]].asUInt64()); } } if(!pMasqueradingVector[7].empty() && pJson.isMember(pMasqueradingVector[7])) { dirtyFlag_[7] = true; if(!pJson[pMasqueradingVector[7]].isNull()) { auto str = pJson[pMasqueradingVector[7]].asString(); tfaSecret_=std::make_shared>(drogon::utils::base64DecodeToVector(str)); } } if(!pMasqueradingVector[8].empty() && pJson.isMember(pMasqueradingVector[8])) { dirtyFlag_[8] = true; if(!pJson[pMasqueradingVector[8]].isNull()) { gitlabAt_=std::make_shared(pJson[pMasqueradingVector[8]].asString()); } } if(!pMasqueradingVector[9].empty() && pJson.isMember(pMasqueradingVector[9])) { dirtyFlag_[9] = true; if(!pJson[pMasqueradingVector[9]].isNull()) { gitlabRt_=std::make_shared(pJson[pMasqueradingVector[9]].asString()); } } } void User::updateByJson(const Json::Value &pJson) noexcept(false) { if(pJson.isMember("id")) { if(!pJson["id"].isNull()) { id_=std::make_shared((uint64_t)pJson["id"].asUInt64()); } } if(pJson.isMember("gitlab")) { dirtyFlag_[1] = true; if(!pJson["gitlab"].isNull()) { gitlab_=std::make_shared((uint64_t)pJson["gitlab"].asUInt64()); } } if(pJson.isMember("name")) { dirtyFlag_[2] = true; if(!pJson["name"].isNull()) { name_=std::make_shared(pJson["name"].asString()); } } if(pJson.isMember("password")) { dirtyFlag_[3] = true; if(!pJson["password"].isNull()) { password_=std::make_shared(pJson["password"].asString()); } } if(pJson.isMember("role")) { dirtyFlag_[4] = true; if(!pJson["role"].isNull()) { role_=std::make_shared((uint64_t)pJson["role"].asUInt64()); } } if(pJson.isMember("root_id")) { dirtyFlag_[5] = true; if(!pJson["root_id"].isNull()) { rootId_=std::make_shared((uint64_t)pJson["root_id"].asUInt64()); } } if(pJson.isMember("tfa_type")) { dirtyFlag_[6] = true; if(!pJson["tfa_type"].isNull()) { tfaType_=std::make_shared((uint64_t)pJson["tfa_type"].asUInt64()); } } if(pJson.isMember("tfa_secret")) { dirtyFlag_[7] = true; if(!pJson["tfa_secret"].isNull()) { auto str = pJson["tfa_secret"].asString(); tfaSecret_=std::make_shared>(drogon::utils::base64DecodeToVector(str)); } } if(pJson.isMember("gitlab_at")) { dirtyFlag_[8] = true; if(!pJson["gitlab_at"].isNull()) { gitlabAt_=std::make_shared(pJson["gitlab_at"].asString()); } } if(pJson.isMember("gitlab_rt")) { dirtyFlag_[9] = true; if(!pJson["gitlab_rt"].isNull()) { gitlabRt_=std::make_shared(pJson["gitlab_rt"].asString()); } } } const uint64_t &User::getValueOfId() const noexcept { const static uint64_t defaultValue = uint64_t(); if(id_) return *id_; return defaultValue; } const std::shared_ptr &User::getId() const noexcept { return id_; } void User::setId(const uint64_t &pId) noexcept { id_ = std::make_shared(pId); dirtyFlag_[0] = true; } const typename User::PrimaryKeyType & User::getPrimaryKey() const { assert(id_); return *id_; } const uint64_t &User::getValueOfGitlab() const noexcept { const static uint64_t defaultValue = uint64_t(); if(gitlab_) return *gitlab_; return defaultValue; } const std::shared_ptr &User::getGitlab() const noexcept { return gitlab_; } void User::setGitlab(const uint64_t &pGitlab) noexcept { gitlab_ = std::make_shared(pGitlab); dirtyFlag_[1] = true; } const std::string &User::getValueOfName() const noexcept { const static std::string defaultValue = std::string(); if(name_) return *name_; return defaultValue; } const std::shared_ptr &User::getName() const noexcept { return name_; } void User::setName(const std::string &pName) noexcept { name_ = std::make_shared(pName); dirtyFlag_[2] = true; } void User::setName(std::string &&pName) noexcept { name_ = std::make_shared(std::move(pName)); dirtyFlag_[2] = true; } const std::string &User::getValueOfPassword() const noexcept { const static std::string defaultValue = std::string(); if(password_) return *password_; return defaultValue; } const std::shared_ptr &User::getPassword() const noexcept { return password_; } void User::setPassword(const std::string &pPassword) noexcept { password_ = std::make_shared(pPassword); dirtyFlag_[3] = true; } void User::setPassword(std::string &&pPassword) noexcept { password_ = std::make_shared(std::move(pPassword)); dirtyFlag_[3] = true; } const uint64_t &User::getValueOfRole() const noexcept { const static uint64_t defaultValue = uint64_t(); if(role_) return *role_; return defaultValue; } const std::shared_ptr &User::getRole() const noexcept { return role_; } void User::setRole(const uint64_t &pRole) noexcept { role_ = std::make_shared(pRole); dirtyFlag_[4] = true; } const uint64_t &User::getValueOfRootId() const noexcept { const static uint64_t defaultValue = uint64_t(); if(rootId_) return *rootId_; return defaultValue; } const std::shared_ptr &User::getRootId() const noexcept { return rootId_; } void User::setRootId(const uint64_t &pRootId) noexcept { rootId_ = std::make_shared(pRootId); dirtyFlag_[5] = true; } const uint64_t &User::getValueOfTfaType() const noexcept { const static uint64_t defaultValue = uint64_t(); if(tfaType_) return *tfaType_; return defaultValue; } const std::shared_ptr &User::getTfaType() const noexcept { return tfaType_; } void User::setTfaType(const uint64_t &pTfaType) noexcept { tfaType_ = std::make_shared(pTfaType); dirtyFlag_[6] = true; } const std::vector &User::getValueOfTfaSecret() const noexcept { const static std::vector defaultValue = std::vector(); if(tfaSecret_) return *tfaSecret_; return defaultValue; } std::string User::getValueOfTfaSecretAsString() const noexcept { const static std::string defaultValue = std::string(); if(tfaSecret_) return std::string(tfaSecret_->data(),tfaSecret_->size()); return defaultValue; } const std::shared_ptr> &User::getTfaSecret() const noexcept { return tfaSecret_; } void User::setTfaSecret(const std::vector &pTfaSecret) noexcept { tfaSecret_ = std::make_shared>(pTfaSecret); dirtyFlag_[7] = true; } void User::setTfaSecret(const std::string &pTfaSecret) noexcept { tfaSecret_ = std::make_shared>(pTfaSecret.c_str(),pTfaSecret.c_str()+pTfaSecret.length()); dirtyFlag_[7] = true; } void User::setTfaSecretToNull() noexcept { tfaSecret_.reset(); dirtyFlag_[7] = true; } const std::string &User::getValueOfGitlabAt() const noexcept { const static std::string defaultValue = std::string(); if(gitlabAt_) return *gitlabAt_; return defaultValue; } const std::shared_ptr &User::getGitlabAt() const noexcept { return gitlabAt_; } void User::setGitlabAt(const std::string &pGitlabAt) noexcept { gitlabAt_ = std::make_shared(pGitlabAt); dirtyFlag_[8] = true; } void User::setGitlabAt(std::string &&pGitlabAt) noexcept { gitlabAt_ = std::make_shared(std::move(pGitlabAt)); dirtyFlag_[8] = true; } void User::setGitlabAtToNull() noexcept { gitlabAt_.reset(); dirtyFlag_[8] = true; } const std::string &User::getValueOfGitlabRt() const noexcept { const static std::string defaultValue = std::string(); if(gitlabRt_) return *gitlabRt_; return defaultValue; } const std::shared_ptr &User::getGitlabRt() const noexcept { return gitlabRt_; } void User::setGitlabRt(const std::string &pGitlabRt) noexcept { gitlabRt_ = std::make_shared(pGitlabRt); dirtyFlag_[9] = true; } void User::setGitlabRt(std::string &&pGitlabRt) noexcept { gitlabRt_ = std::make_shared(std::move(pGitlabRt)); dirtyFlag_[9] = true; } void User::setGitlabRtToNull() noexcept { gitlabRt_.reset(); dirtyFlag_[9] = true; } void User::updateId(const uint64_t id) { id_ = std::make_shared(id); } const std::vector &User::insertColumns() noexcept { static const std::vector inCols={ "gitlab", "name", "password", "role", "root_id", "tfa_type", "tfa_secret", "gitlab_at", "gitlab_rt" }; return inCols; } void User::outputArgs(drogon::orm::internal::SqlBinder &binder) const { if(dirtyFlag_[1]) { if(getGitlab()) { binder << getValueOfGitlab(); } else { binder << nullptr; } } if(dirtyFlag_[2]) { if(getName()) { binder << getValueOfName(); } else { binder << nullptr; } } if(dirtyFlag_[3]) { if(getPassword()) { binder << getValueOfPassword(); } else { binder << nullptr; } } if(dirtyFlag_[4]) { if(getRole()) { binder << getValueOfRole(); } else { binder << nullptr; } } if(dirtyFlag_[5]) { if(getRootId()) { binder << getValueOfRootId(); } else { binder << nullptr; } } if(dirtyFlag_[6]) { if(getTfaType()) { binder << getValueOfTfaType(); } else { binder << nullptr; } } if(dirtyFlag_[7]) { if(getTfaSecret()) { binder << getValueOfTfaSecret(); } else { binder << nullptr; } } if(dirtyFlag_[8]) { if(getGitlabAt()) { binder << getValueOfGitlabAt(); } else { binder << nullptr; } } if(dirtyFlag_[9]) { if(getGitlabRt()) { binder << getValueOfGitlabRt(); } else { binder << nullptr; } } } const std::vector User::updateColumns() const { std::vector ret; if(dirtyFlag_[1]) { ret.push_back(getColumnName(1)); } if(dirtyFlag_[2]) { ret.push_back(getColumnName(2)); } if(dirtyFlag_[3]) { ret.push_back(getColumnName(3)); } if(dirtyFlag_[4]) { ret.push_back(getColumnName(4)); } if(dirtyFlag_[5]) { ret.push_back(getColumnName(5)); } if(dirtyFlag_[6]) { ret.push_back(getColumnName(6)); } if(dirtyFlag_[7]) { ret.push_back(getColumnName(7)); } if(dirtyFlag_[8]) { ret.push_back(getColumnName(8)); } if(dirtyFlag_[9]) { ret.push_back(getColumnName(9)); } return ret; } void User::updateArgs(drogon::orm::internal::SqlBinder &binder) const { if(dirtyFlag_[1]) { if(getGitlab()) { binder << getValueOfGitlab(); } else { binder << nullptr; } } if(dirtyFlag_[2]) { if(getName()) { binder << getValueOfName(); } else { binder << nullptr; } } if(dirtyFlag_[3]) { if(getPassword()) { binder << getValueOfPassword(); } else { binder << nullptr; } } if(dirtyFlag_[4]) { if(getRole()) { binder << getValueOfRole(); } else { binder << nullptr; } } if(dirtyFlag_[5]) { if(getRootId()) { binder << getValueOfRootId(); } else { binder << nullptr; } } if(dirtyFlag_[6]) { if(getTfaType()) { binder << getValueOfTfaType(); } else { binder << nullptr; } } if(dirtyFlag_[7]) { if(getTfaSecret()) { binder << getValueOfTfaSecret(); } else { binder << nullptr; } } if(dirtyFlag_[8]) { if(getGitlabAt()) { binder << getValueOfGitlabAt(); } else { binder << nullptr; } } if(dirtyFlag_[9]) { if(getGitlabRt()) { binder << getValueOfGitlabRt(); } else { binder << nullptr; } } } Json::Value User::toJson() const { Json::Value ret; if(getId()) { ret["id"]=(Json::UInt64)getValueOfId(); } else { ret["id"]=Json::Value(); } if(getGitlab()) { ret["gitlab"]=(Json::UInt64)getValueOfGitlab(); } else { ret["gitlab"]=Json::Value(); } if(getName()) { ret["name"]=getValueOfName(); } else { ret["name"]=Json::Value(); } if(getPassword()) { ret["password"]=getValueOfPassword(); } else { ret["password"]=Json::Value(); } if(getRole()) { ret["role"]=(Json::UInt64)getValueOfRole(); } else { ret["role"]=Json::Value(); } if(getRootId()) { ret["root_id"]=(Json::UInt64)getValueOfRootId(); } else { ret["root_id"]=Json::Value(); } if(getTfaType()) { ret["tfa_type"]=(Json::UInt64)getValueOfTfaType(); } else { ret["tfa_type"]=Json::Value(); } if(getTfaSecret()) { ret["tfa_secret"]=drogon::utils::base64Encode((const unsigned char *)getTfaSecret()->data(),getTfaSecret()->size()); } else { ret["tfa_secret"]=Json::Value(); } if(getGitlabAt()) { ret["gitlab_at"]=getValueOfGitlabAt(); } else { ret["gitlab_at"]=Json::Value(); } if(getGitlabRt()) { ret["gitlab_rt"]=getValueOfGitlabRt(); } else { ret["gitlab_rt"]=Json::Value(); } return ret; } Json::Value User::toMasqueradedJson( const std::vector &pMasqueradingVector) const { Json::Value ret; if(pMasqueradingVector.size() == 10) { if(!pMasqueradingVector[0].empty()) { if(getId()) { ret[pMasqueradingVector[0]]=(Json::UInt64)getValueOfId(); } else { ret[pMasqueradingVector[0]]=Json::Value(); } } if(!pMasqueradingVector[1].empty()) { if(getGitlab()) { ret[pMasqueradingVector[1]]=(Json::UInt64)getValueOfGitlab(); } else { ret[pMasqueradingVector[1]]=Json::Value(); } } if(!pMasqueradingVector[2].empty()) { if(getName()) { ret[pMasqueradingVector[2]]=getValueOfName(); } else { ret[pMasqueradingVector[2]]=Json::Value(); } } if(!pMasqueradingVector[3].empty()) { if(getPassword()) { ret[pMasqueradingVector[3]]=getValueOfPassword(); } else { ret[pMasqueradingVector[3]]=Json::Value(); } } if(!pMasqueradingVector[4].empty()) { if(getRole()) { ret[pMasqueradingVector[4]]=(Json::UInt64)getValueOfRole(); } else { ret[pMasqueradingVector[4]]=Json::Value(); } } if(!pMasqueradingVector[5].empty()) { if(getRootId()) { ret[pMasqueradingVector[5]]=(Json::UInt64)getValueOfRootId(); } else { ret[pMasqueradingVector[5]]=Json::Value(); } } if(!pMasqueradingVector[6].empty()) { if(getTfaType()) { ret[pMasqueradingVector[6]]=(Json::UInt64)getValueOfTfaType(); } else { ret[pMasqueradingVector[6]]=Json::Value(); } } if(!pMasqueradingVector[7].empty()) { if(getTfaSecret()) { ret[pMasqueradingVector[7]]=drogon::utils::base64Encode((const unsigned char *)getTfaSecret()->data(),getTfaSecret()->size()); } else { ret[pMasqueradingVector[7]]=Json::Value(); } } if(!pMasqueradingVector[8].empty()) { if(getGitlabAt()) { ret[pMasqueradingVector[8]]=getValueOfGitlabAt(); } else { ret[pMasqueradingVector[8]]=Json::Value(); } } if(!pMasqueradingVector[9].empty()) { if(getGitlabRt()) { ret[pMasqueradingVector[9]]=getValueOfGitlabRt(); } else { ret[pMasqueradingVector[9]]=Json::Value(); } } return ret; } LOG_ERROR << "Masquerade failed"; if(getId()) { ret["id"]=(Json::UInt64)getValueOfId(); } else { ret["id"]=Json::Value(); } if(getGitlab()) { ret["gitlab"]=(Json::UInt64)getValueOfGitlab(); } else { ret["gitlab"]=Json::Value(); } if(getName()) { ret["name"]=getValueOfName(); } else { ret["name"]=Json::Value(); } if(getPassword()) { ret["password"]=getValueOfPassword(); } else { ret["password"]=Json::Value(); } if(getRole()) { ret["role"]=(Json::UInt64)getValueOfRole(); } else { ret["role"]=Json::Value(); } if(getRootId()) { ret["root_id"]=(Json::UInt64)getValueOfRootId(); } else { ret["root_id"]=Json::Value(); } if(getTfaType()) { ret["tfa_type"]=(Json::UInt64)getValueOfTfaType(); } else { ret["tfa_type"]=Json::Value(); } if(getTfaSecret()) { ret["tfa_secret"]=drogon::utils::base64Encode((const unsigned char *)getTfaSecret()->data(),getTfaSecret()->size()); } else { ret["tfa_secret"]=Json::Value(); } if(getGitlabAt()) { ret["gitlab_at"]=getValueOfGitlabAt(); } else { ret["gitlab_at"]=Json::Value(); } if(getGitlabRt()) { ret["gitlab_rt"]=getValueOfGitlabRt(); } else { ret["gitlab_rt"]=Json::Value(); } return ret; } bool User::validateJsonForCreation(const Json::Value &pJson, std::string &err) { if(pJson.isMember("id")) { if(!validJsonOfField(0, "id", pJson["id"], err, true)) return false; } if(pJson.isMember("gitlab")) { if(!validJsonOfField(1, "gitlab", pJson["gitlab"], err, true)) return false; } else { err="The gitlab column cannot be null"; return false; } if(pJson.isMember("name")) { if(!validJsonOfField(2, "name", pJson["name"], err, true)) return false; } else { err="The name column cannot be null"; return false; } if(pJson.isMember("password")) { if(!validJsonOfField(3, "password", pJson["password"], err, true)) return false; } else { err="The password column cannot be null"; return false; } if(pJson.isMember("role")) { if(!validJsonOfField(4, "role", pJson["role"], err, true)) return false; } else { err="The role column cannot be null"; return false; } if(pJson.isMember("root_id")) { if(!validJsonOfField(5, "root_id", pJson["root_id"], err, true)) return false; } else { err="The root_id column cannot be null"; return false; } if(pJson.isMember("tfa_type")) { if(!validJsonOfField(6, "tfa_type", pJson["tfa_type"], err, true)) return false; } else { err="The tfa_type column cannot be null"; return false; } if(pJson.isMember("tfa_secret")) { if(!validJsonOfField(7, "tfa_secret", pJson["tfa_secret"], err, true)) return false; } if(pJson.isMember("gitlab_at")) { if(!validJsonOfField(8, "gitlab_at", pJson["gitlab_at"], err, true)) return false; } if(pJson.isMember("gitlab_rt")) { if(!validJsonOfField(9, "gitlab_rt", pJson["gitlab_rt"], err, true)) return false; } return true; } bool User::validateMasqueradedJsonForCreation(const Json::Value &pJson, const std::vector &pMasqueradingVector, std::string &err) { if(pMasqueradingVector.size() != 10) { err = "Bad masquerading vector"; return false; } try { if(!pMasqueradingVector[0].empty()) { if(pJson.isMember(pMasqueradingVector[0])) { if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, true)) return false; } } if(!pMasqueradingVector[1].empty()) { if(pJson.isMember(pMasqueradingVector[1])) { if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, true)) return false; } else { err="The " + pMasqueradingVector[1] + " column cannot be null"; return false; } } if(!pMasqueradingVector[2].empty()) { if(pJson.isMember(pMasqueradingVector[2])) { if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, true)) return false; } else { err="The " + pMasqueradingVector[2] + " column cannot be null"; return false; } } if(!pMasqueradingVector[3].empty()) { if(pJson.isMember(pMasqueradingVector[3])) { if(!validJsonOfField(3, pMasqueradingVector[3], pJson[pMasqueradingVector[3]], err, true)) return false; } else { err="The " + pMasqueradingVector[3] + " column cannot be null"; return false; } } if(!pMasqueradingVector[4].empty()) { if(pJson.isMember(pMasqueradingVector[4])) { if(!validJsonOfField(4, pMasqueradingVector[4], pJson[pMasqueradingVector[4]], err, true)) return false; } else { err="The " + pMasqueradingVector[4] + " column cannot be null"; return false; } } if(!pMasqueradingVector[5].empty()) { if(pJson.isMember(pMasqueradingVector[5])) { if(!validJsonOfField(5, pMasqueradingVector[5], pJson[pMasqueradingVector[5]], err, true)) return false; } else { err="The " + pMasqueradingVector[5] + " column cannot be null"; return false; } } if(!pMasqueradingVector[6].empty()) { if(pJson.isMember(pMasqueradingVector[6])) { if(!validJsonOfField(6, pMasqueradingVector[6], pJson[pMasqueradingVector[6]], err, true)) return false; } else { err="The " + pMasqueradingVector[6] + " column cannot be null"; return false; } } if(!pMasqueradingVector[7].empty()) { if(pJson.isMember(pMasqueradingVector[7])) { if(!validJsonOfField(7, pMasqueradingVector[7], pJson[pMasqueradingVector[7]], err, true)) return false; } } if(!pMasqueradingVector[8].empty()) { if(pJson.isMember(pMasqueradingVector[8])) { if(!validJsonOfField(8, pMasqueradingVector[8], pJson[pMasqueradingVector[8]], err, true)) return false; } } if(!pMasqueradingVector[9].empty()) { if(pJson.isMember(pMasqueradingVector[9])) { if(!validJsonOfField(9, pMasqueradingVector[9], pJson[pMasqueradingVector[9]], err, true)) return false; } } } catch(const Json::LogicError &e) { err = e.what(); return false; } return true; } bool User::validateJsonForUpdate(const Json::Value &pJson, std::string &err) { if(pJson.isMember("id")) { if(!validJsonOfField(0, "id", pJson["id"], err, false)) return false; } else { err = "The value of primary key must be set in the json object for update"; return false; } if(pJson.isMember("gitlab")) { if(!validJsonOfField(1, "gitlab", pJson["gitlab"], err, false)) return false; } if(pJson.isMember("name")) { if(!validJsonOfField(2, "name", pJson["name"], err, false)) return false; } if(pJson.isMember("password")) { if(!validJsonOfField(3, "password", pJson["password"], err, false)) return false; } if(pJson.isMember("role")) { if(!validJsonOfField(4, "role", pJson["role"], err, false)) return false; } if(pJson.isMember("root_id")) { if(!validJsonOfField(5, "root_id", pJson["root_id"], err, false)) return false; } if(pJson.isMember("tfa_type")) { if(!validJsonOfField(6, "tfa_type", pJson["tfa_type"], err, false)) return false; } if(pJson.isMember("tfa_secret")) { if(!validJsonOfField(7, "tfa_secret", pJson["tfa_secret"], err, false)) return false; } if(pJson.isMember("gitlab_at")) { if(!validJsonOfField(8, "gitlab_at", pJson["gitlab_at"], err, false)) return false; } if(pJson.isMember("gitlab_rt")) { if(!validJsonOfField(9, "gitlab_rt", pJson["gitlab_rt"], err, false)) return false; } return true; } bool User::validateMasqueradedJsonForUpdate(const Json::Value &pJson, const std::vector &pMasqueradingVector, std::string &err) { if(pMasqueradingVector.size() != 10) { err = "Bad masquerading vector"; return false; } try { if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0])) { if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, false)) return false; } else { err = "The value of primary key must be set in the json object for update"; return false; } if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1])) { if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, false)) return false; } if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2])) { if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, false)) return false; } if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3])) { if(!validJsonOfField(3, pMasqueradingVector[3], pJson[pMasqueradingVector[3]], err, false)) return false; } if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4])) { if(!validJsonOfField(4, pMasqueradingVector[4], pJson[pMasqueradingVector[4]], err, false)) return false; } if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5])) { if(!validJsonOfField(5, pMasqueradingVector[5], pJson[pMasqueradingVector[5]], err, false)) return false; } if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6])) { if(!validJsonOfField(6, pMasqueradingVector[6], pJson[pMasqueradingVector[6]], err, false)) return false; } if(!pMasqueradingVector[7].empty() && pJson.isMember(pMasqueradingVector[7])) { if(!validJsonOfField(7, pMasqueradingVector[7], pJson[pMasqueradingVector[7]], err, false)) return false; } if(!pMasqueradingVector[8].empty() && pJson.isMember(pMasqueradingVector[8])) { if(!validJsonOfField(8, pMasqueradingVector[8], pJson[pMasqueradingVector[8]], err, false)) return false; } if(!pMasqueradingVector[9].empty() && pJson.isMember(pMasqueradingVector[9])) { if(!validJsonOfField(9, pMasqueradingVector[9], pJson[pMasqueradingVector[9]], err, false)) return false; } } catch(const Json::LogicError &e) { err = e.what(); return false; } return true; } bool User::validJsonOfField(size_t index, const std::string &fieldName, const Json::Value &pJson, std::string &err, bool isForCreation) { switch(index) { case 0: if(pJson.isNull()) { err="The " + fieldName + " column cannot be null"; return false; } if(isForCreation) { err="The automatic primary key cannot be set"; return false; } if(!pJson.isUInt64()) { err="Type error in the "+fieldName+" field"; return false; } break; case 1: if(pJson.isNull()) { err="The " + fieldName + " column cannot be null"; return false; } if(!pJson.isUInt64()) { err="Type error in the "+fieldName+" field"; return false; } break; case 2: if(pJson.isNull()) { err="The " + fieldName + " column cannot be null"; return false; } if(!pJson.isString()) { err="Type error in the "+fieldName+" field"; return false; } break; case 3: if(pJson.isNull()) { err="The " + fieldName + " column cannot be null"; return false; } if(!pJson.isString()) { err="Type error in the "+fieldName+" field"; return false; } break; case 4: if(pJson.isNull()) { err="The " + fieldName + " column cannot be null"; return false; } if(!pJson.isUInt64()) { err="Type error in the "+fieldName+" field"; return false; } break; case 5: if(pJson.isNull()) { err="The " + fieldName + " column cannot be null"; return false; } if(!pJson.isUInt64()) { err="Type error in the "+fieldName+" field"; return false; } break; case 6: if(pJson.isNull()) { err="The " + fieldName + " column cannot be null"; return false; } if(!pJson.isUInt64()) { err="Type error in the "+fieldName+" field"; return false; } break; case 7: if(pJson.isNull()) { return true; } if(!pJson.isString()) { err="Type error in the "+fieldName+" field"; return false; } break; case 8: if(pJson.isNull()) { return true; } if(!pJson.isString()) { err="Type error in the "+fieldName+" field"; return false; } break; case 9: if(pJson.isNull()) { return true; } if(!pJson.isString()) { err="Type error in the "+fieldName+" field"; return false; } break; default: err="Internal error in the server"; return false; break; } return true; }