Fixing typo in UserInfo struct

This commit is contained in:
stephb9959
2022-01-05 22:16:25 -08:00
parent 08a50db13c
commit f8c6dad974
18 changed files with 93 additions and 72 deletions

View File

@@ -31,7 +31,7 @@ namespace OpenWifi {
*/
static inline bool Can( const SecurityObjects::UserInfo & User, const SecurityObjects::UserInfo & Target, ACL_OPS Op) {
// rule 1
if(User.Id == Target.Id && Op==DELETE)
if(User.id == Target.id && Op==DELETE)
return false;
// rule 2
@@ -39,7 +39,7 @@ namespace OpenWifi {
return true;
// rule 3
if(User.Id == Target.Id)
if(User.id == Target.id)
return true;
// rule 4
@@ -72,7 +72,6 @@ namespace OpenWifi {
return false;
}
return true;
}
private:

View File

@@ -238,15 +238,15 @@ namespace OpenWifi {
UInfo.webtoken.expires_in_ = TokenAging_ ;
UInfo.webtoken.idle_timeout_ = 5 * 60;
UInfo.webtoken.token_type_ = "Bearer";
UInfo.webtoken.access_token_ = GenerateTokenHMAC(UInfo.userinfo.Id,USERNAME);
UInfo.webtoken.id_token_ = GenerateTokenHMAC(UInfo.userinfo.Id,USERNAME);
UInfo.webtoken.refresh_token_ = GenerateTokenHMAC(UInfo.userinfo.Id,CUSTOM);
UInfo.webtoken.access_token_ = GenerateTokenHMAC(UInfo.userinfo.id,USERNAME);
UInfo.webtoken.id_token_ = GenerateTokenHMAC(UInfo.userinfo.id,USERNAME);
UInfo.webtoken.refresh_token_ = GenerateTokenHMAC(UInfo.userinfo.id,CUSTOM);
UInfo.webtoken.created_ = time(nullptr);
UInfo.webtoken.username_ = UserName;
UInfo.webtoken.errorCode = 0;
UInfo.webtoken.userMustChangePassword = false;
StorageService()->UserDB().SetLastLogin(UInfo.userinfo.Id);
StorageService()->UserTokenDB().AddToken(UInfo.userinfo.Id, UInfo.webtoken.access_token_,
StorageService()->UserDB().SetLastLogin(UInfo.userinfo.id);
StorageService()->UserTokenDB().AddToken(UInfo.userinfo.id, UInfo.webtoken.access_token_,
UInfo.webtoken.refresh_token_, UInfo.webtoken.token_type_,
UInfo.webtoken.expires_in_, UInfo.webtoken.idle_timeout_);
}
@@ -261,15 +261,15 @@ namespace OpenWifi {
UInfo.webtoken.expires_in_ = TokenAging_ ;
UInfo.webtoken.idle_timeout_ = 5 * 60;
UInfo.webtoken.token_type_ = "Bearer";
UInfo.webtoken.access_token_ = GenerateTokenHMAC(UInfo.userinfo.Id,USERNAME);
UInfo.webtoken.id_token_ = GenerateTokenHMAC(UInfo.userinfo.Id,USERNAME);
UInfo.webtoken.refresh_token_ = GenerateTokenHMAC(UInfo.userinfo.Id,CUSTOM);
UInfo.webtoken.access_token_ = GenerateTokenHMAC(UInfo.userinfo.id,USERNAME);
UInfo.webtoken.id_token_ = GenerateTokenHMAC(UInfo.userinfo.id,USERNAME);
UInfo.webtoken.refresh_token_ = GenerateTokenHMAC(UInfo.userinfo.id,CUSTOM);
UInfo.webtoken.created_ = time(nullptr);
UInfo.webtoken.username_ = UserName;
UInfo.webtoken.errorCode = 0;
UInfo.webtoken.userMustChangePassword = false;
StorageService()->SubDB().SetLastLogin(UInfo.userinfo.Id);
StorageService()->SubTokenDB().AddToken(UInfo.userinfo.Id, UInfo.webtoken.access_token_,
StorageService()->SubDB().SetLastLogin(UInfo.userinfo.id);
StorageService()->SubTokenDB().AddToken(UInfo.userinfo.id, UInfo.webtoken.access_token_,
UInfo.webtoken.refresh_token_, UInfo.webtoken.token_type_,
UInfo.webtoken.expires_in_, UInfo.webtoken.idle_timeout_);
}
@@ -419,12 +419,12 @@ namespace OpenWifi {
}
UInfo.userinfo.lastPasswordChange = std::time(nullptr);
UInfo.userinfo.changePassword = false;
StorageService()->UserDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.Id,UInfo.userinfo);
StorageService()->UserDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo);
}
// so we have a good password, password up date has taken place if need be, now generate the token.
UInfo.userinfo.lastLogin=std::time(nullptr);
StorageService()->UserDB().SetLastLogin(UInfo.userinfo.Id);
StorageService()->UserDB().SetLastLogin(UInfo.userinfo.id);
CreateToken(UserName, UInfo );
return SUCCESS;
@@ -464,12 +464,12 @@ namespace OpenWifi {
}
UInfo.userinfo.lastPasswordChange = std::time(nullptr);
UInfo.userinfo.changePassword = false;
StorageService()->SubDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.Id,UInfo.userinfo);
StorageService()->SubDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo);
}
// so we have a good password, password up date has taken place if need be, now generate the token.
UInfo.userinfo.lastLogin=std::time(nullptr);
StorageService()->SubDB().SetLastLogin(UInfo.userinfo.Id);
StorageService()->SubDB().SetLastLogin(UInfo.userinfo.id);
CreateSubToken(UserName, UInfo );
return SUCCESS;

View File

@@ -27,7 +27,7 @@ namespace OpenWifi {
};
void RESTAPI_avatar_handler::DoPost() {
std::string Id = UserInfo_.userinfo.Id;
std::string Id = UserInfo_.userinfo.id;
SecurityObjects::UserInfo UInfo;
std::stringstream SS;
@@ -66,7 +66,7 @@ namespace OpenWifi {
void RESTAPI_avatar_handler::DoDelete() {
std::string Id = GetBinding(RESTAPI::Protocol::ID, "");
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && Id!=UserInfo_.userinfo.Id) {
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && Id!=UserInfo_.userinfo.id) {
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
}

View File

@@ -81,7 +81,7 @@ namespace OpenWifi {
NewLink.action = OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD;
NewLink.id = MicroService::CreateUUID();
NewLink.userId = UInfo1.Id;
NewLink.userId = UInfo1.id;
NewLink.created = std::time(nullptr);
NewLink.expires = NewLink.created + (24*60*60);
StorageService()->ActionLinksDB().CreateAction(NewLink);

View File

@@ -10,7 +10,7 @@ namespace OpenWifi {
void RESTAPI_preferences::DoGet() {
SecurityObjects::Preferences P;
Poco::JSON::Object Answer;
StorageService()->PreferencesDB().GetPreferences(UserInfo_.userinfo.Id, P);
StorageService()->PreferencesDB().GetPreferences(UserInfo_.userinfo.id, P);
P.to_json(Answer);
ReturnObject(Answer);
}
@@ -24,7 +24,7 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
P.id = UserInfo_.userinfo.Id;
P.id = UserInfo_.userinfo.id;
P.modified = std::time(nullptr);
StorageService()->PreferencesDB().SetPreferences(P);

View File

@@ -27,7 +27,7 @@ namespace OpenWifi {
};
void RESTAPI_subavatar_handler::DoPost() {
std::string Id = UserInfo_.userinfo.Id;
std::string Id = UserInfo_.userinfo.id;
SecurityObjects::UserInfo UInfo;
std::stringstream SS;
@@ -66,7 +66,7 @@ namespace OpenWifi {
void RESTAPI_subavatar_handler::DoDelete() {
std::string Id = GetBinding(RESTAPI::Protocol::ID, "");
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && Id!=UserInfo_.userinfo.Id) {
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && Id!=UserInfo_.userinfo.id) {
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
}

View File

@@ -12,11 +12,11 @@ namespace OpenWifi {
SecurityObjects::UserInfo User;
// std::cout << "submfa get " << UserInfo_.userinfo.Id << " user:" << UserInfo_.userinfo.email << std::endl;
if (StorageService()->SubDB().GetUserById(UserInfo_.userinfo.Id,User)) {
if (StorageService()->SubDB().GetUserById(UserInfo_.userinfo.id,User)) {
Poco::JSON::Object Answer;
SecurityObjects::SubMfaConfig MFC;
MFC.id = User.Id;
MFC.id = User.id;
if(User.userTypeProprietaryInfo.mfa.enabled) {
if(User.userTypeProprietaryInfo.mfa.method == "sms") {
MFC.sms = User.userTypeProprietaryInfo.mobiles[0].number;
@@ -47,9 +47,9 @@ namespace OpenWifi {
if (MFC.type == "disabled") {
SecurityObjects::UserInfo User;
StorageService()->SubDB().GetUserById(UserInfo_.userinfo.Id, User);
StorageService()->SubDB().GetUserById(UserInfo_.userinfo.id, User);
User.userTypeProprietaryInfo.mfa.enabled = false;
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.Id, User);
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.id, User);
Poco::JSON::Object Answer;
MFC.to_json(Answer);
@@ -57,10 +57,10 @@ namespace OpenWifi {
} else if (MFC.type == "email") {
SecurityObjects::UserInfo User;
StorageService()->SubDB().GetUserById(UserInfo_.userinfo.Id, User);
StorageService()->SubDB().GetUserById(UserInfo_.userinfo.id, User);
User.userTypeProprietaryInfo.mfa.enabled = true;
User.userTypeProprietaryInfo.mfa.method = "email";
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.Id, User);
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.id, User);
MFC.sms = MFC.sms;
MFC.type = "email";
@@ -93,7 +93,7 @@ namespace OpenWifi {
if (SMSSender()->CompleteValidation(MFC.sms, ChallengeCode, UserInfo_.userinfo.email)) {
SecurityObjects::UserInfo User;
StorageService()->SubDB().GetUserById(UserInfo_.userinfo.Id, User);
StorageService()->SubDB().GetUserById(UserInfo_.userinfo.id, User);
User.userTypeProprietaryInfo.mfa.enabled = true;
User.userTypeProprietaryInfo.mfa.method = "sms";
SecurityObjects::MobilePhoneNumber PhoneNumber;
@@ -103,7 +103,7 @@ namespace OpenWifi {
User.userTypeProprietaryInfo.mobiles.clear();
User.userTypeProprietaryInfo.mobiles.push_back(PhoneNumber);
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.Id, User);
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.id, User);
MFC.sms = MFC.sms;
MFC.type = "sms";

View File

@@ -75,7 +75,7 @@ namespace OpenWifi {
NewLink.action = OpenWifi::SecurityObjects::LinkActions::SUB_FORGOT_PASSWORD;
NewLink.id = MicroService::CreateUUID();
NewLink.userId = UInfo1.Id;
NewLink.userId = UInfo1.id;
NewLink.created = std::time(nullptr);
NewLink.expires = NewLink.created + (24*60*60);
StorageService()->ActionLinksDB().CreateAction(NewLink);

View File

@@ -10,7 +10,7 @@ namespace OpenWifi {
void RESTAPI_subpreferences::DoGet() {
SecurityObjects::Preferences P;
Poco::JSON::Object Answer;
StorageService()->SubPreferencesDB().GetPreferences(UserInfo_.userinfo.Id, P);
StorageService()->SubPreferencesDB().GetPreferences(UserInfo_.userinfo.id, P);
P.to_json(Answer);
ReturnObject(Answer);
}
@@ -24,7 +24,7 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
P.id = UserInfo_.userinfo.Id;
P.id = UserInfo_.userinfo.id;
P.modified = std::time(nullptr);
StorageService()->SubPreferencesDB().SetPreferences(P);

View File

@@ -109,7 +109,7 @@ namespace OpenWifi {
if(GetParameter("email_verification","false")=="true") {
if(AuthService::VerifySubEmail(NewUser))
Logger_.information(Poco::format("Verification e-mail requested for %s",NewUser.email));
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email,NewUser.Id,NewUser);
StorageService()->SubDB().UpdateUserInfo(UserInfo_.userinfo.email,NewUser.id,NewUser);
}
if(!StorageService()->SubDB().GetUserByEmail(NewUser.email, NewUser)) {
@@ -168,7 +168,7 @@ namespace OpenWifi {
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && NewRole==SecurityObjects::ROOT) {
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
}
if(Id==UserInfo_.userinfo.Id) {
if(Id==UserInfo_.userinfo.id) {
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
}
Existing.userRole = NewRole;

View File

@@ -21,7 +21,7 @@ namespace OpenWifi {
for (auto &i : Users) {
Poco::JSON::Object Obj;
if (IdOnly) {
ArrayObj.add(i.Id);
ArrayObj.add(i.id);
} else {
Sanitize(UserInfo_, i);
i.to_json(Obj);
@@ -39,7 +39,7 @@ namespace OpenWifi {
if(StorageService()->SubDB().GetUserById(tI,UInfo)) {
Poco::JSON::Object Obj;
if (IdOnly) {
ArrayObj.add(UInfo.Id);
ArrayObj.add(UInfo.id);
} else {
Sanitize(UserInfo_, UInfo);
UInfo.to_json(Obj);

View File

@@ -111,7 +111,7 @@ namespace OpenWifi {
if(GetParameter("email_verification","false")=="true") {
if(AuthService::VerifyEmail(NewUser))
Logger_.information(Poco::format("Verification e-mail requested for %s",NewUser.email));
StorageService()->UserDB().UpdateUserInfo(UserInfo_.userinfo.email,NewUser.Id,NewUser);
StorageService()->UserDB().UpdateUserInfo(UserInfo_.userinfo.email,NewUser.id,NewUser);
}
if(!StorageService()->UserDB().GetUserByEmail(NewUser.email, NewUser)) {
@@ -174,7 +174,7 @@ namespace OpenWifi {
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT && NewRole==SecurityObjects::ROOT) {
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
}
if(Id==UserInfo_.userinfo.Id) {
if(Id==UserInfo_.userinfo.id) {
return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights, ACCESS_DENIED);
}
Existing.userRole = NewRole;

View File

@@ -20,7 +20,7 @@ namespace OpenWifi {
for (auto &i : Users) {
Poco::JSON::Object Obj;
if (IdOnly) {
ArrayObj.add(i.Id);
ArrayObj.add(i.id);
} else {
Sanitize(UserInfo_, i);
i.to_json(Obj);
@@ -38,7 +38,7 @@ namespace OpenWifi {
if(StorageService()->UserDB().GetUserById(i,UInfo)) {
Poco::JSON::Object Obj;
if (IdOnly) {
ArrayObj.add(UInfo.Id);
ArrayObj.add(UInfo.id);
} else {
Sanitize(UserInfo_, UInfo);
UInfo.to_json(Obj);

View File

@@ -224,7 +224,7 @@ namespace OpenWifi::SecurityObjects {
}
void UserInfo::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"Id",Id);
field_to_json(Obj,"id",id);
field_to_json(Obj,"name",name);
field_to_json(Obj,"description", description);
field_to_json(Obj,"avatar", avatar);
@@ -258,7 +258,7 @@ namespace OpenWifi::SecurityObjects {
bool UserInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj,"Id",Id);
field_from_json(Obj,"id",id);
field_from_json(Obj,"name",name);
field_from_json(Obj,"description",description);
field_from_json(Obj,"avatar",avatar);

View File

@@ -106,7 +106,7 @@ namespace OpenWifi {
};
struct UserInfo {
std::string Id;
std::string id;
std::string name;
std::string description;
std::string avatar;

View File

@@ -20,7 +20,7 @@ namespace OpenWifi {
U.currentPassword = MicroService::instance().ConfigGetString("authentication.default.password", "");
U.lastPasswords.push_back(U.currentPassword);
U.email = MicroService::instance().ConfigGetString("authentication.default.username", "");
U.Id = NewDefaultUseridStockUUID;
U.id = NewDefaultUseridStockUUID;
U.userRole = SecurityObjects::ROOT;
U.creationDate = std::time(nullptr);
U.validated = true;

View File

@@ -93,6 +93,25 @@ namespace OpenWifi {
UsersOnly_(Users) {
}
bool BaseUserDB::Upgrade(int from, int &to, const std::string & TableName) {
auto Session = Pool_.get();
Poco::Data::Statement S(Session);
S << "alter table " + TableName + " rename column owner to entity;", Poco::Data::Keywords::now;
S.reset(Session);
S << "alter table " + TableName + " rename column oauth to deviceList;", Poco::Data::Keywords::now;
S.reset(Session);
S << "alter table " + TableName + " rename column oauthuserinfo to loginRecords;", Poco::Data::Keywords::now;
S.reset(Session);
S << "alter table " + TableName + " add column modified BIGINT;", Poco::Data::Keywords::now;
S.reset(Session);
to = 1;
return true;
}
bool BaseUserDB::CreateUser(const std::string & Admin, SecurityObjects::UserInfo & NewUser, bool PasswordHashedAlready ) {
try {
Poco::toLowerInPlace(NewUser.email);
@@ -103,7 +122,7 @@ namespace OpenWifi {
Poco::Data::Session Sess = Pool_.get();
if(!PasswordHashedAlready) {
NewUser.Id = MicroService::CreateUUID();
NewUser.id = MicroService::CreateUUID();
NewUser.creationDate = std::time(nullptr);
}
@@ -221,12 +240,12 @@ namespace OpenWifi {
void UserCache::UpdateCache(const SecurityObjects::UserInfo &R) {
// std::cout << "Update user cache:" << R.Id << std::endl;
CacheById_->update(R.Id,R);
CacheByEMail_->update(R.email,R.Id);
CacheById_->update(R.id,R);
CacheByEMail_->update(R.email,R.id);
if(UsersOnly_)
StorageService()->UserTokenDB().DeleteRecordsFromCache("userName", R.Id);
StorageService()->UserTokenDB().DeleteRecordsFromCache("userName", R.id);
else
StorageService()->SubTokenDB().DeleteRecordsFromCache("userName", R.Id);
StorageService()->SubTokenDB().DeleteRecordsFromCache("userName", R.id);
}
inline void UserCache::Create(const SecurityObjects::UserInfo &R) {
@@ -274,7 +293,7 @@ namespace OpenWifi {
template<> void ORM::DB<OpenWifi::UserInfoRecordTuple,
OpenWifi::SecurityObjects::UserInfo>::Convert(OpenWifi::UserInfoRecordTuple &T,
OpenWifi::SecurityObjects::UserInfo &U) {
U.Id = T.get<0>();
U.id = T.get<0>();
U.name = T.get<1>();
U.description = T.get<2>();
U.avatar = T.get<3>();
@@ -309,7 +328,7 @@ template<> void ORM::DB<OpenWifi::UserInfoRecordTuple,
template<> void ORM::DB< OpenWifi::UserInfoRecordTuple,
OpenWifi::SecurityObjects::UserInfo>::Convert(OpenWifi::SecurityObjects::UserInfo &U,
OpenWifi::UserInfoRecordTuple &T) {
T.set<0>(U.Id);
T.set<0>(U.id);
T.set<1>(U.name);
T.set<2>(U.description);
T.set<3>(U.avatar);

View File

@@ -73,6 +73,9 @@ namespace OpenWifi {
bool SetLastLogin(const std::string &Id);
bool SetAvatar(const std::string &Id, const std::string &Value);
inline int Version() { return 1;}
bool Upgrade(int from, int &to, const std::string & Name);
bool UsersOnly_;
};