Framework update + added modified to userrecord.

This commit is contained in:
stephb9959
2022-01-10 23:40:45 -08:00
parent 30431ab954
commit c47e9bc98d
8 changed files with 49 additions and 8 deletions

View File

@@ -423,6 +423,7 @@ namespace OpenWifi {
} }
UInfo.userinfo.lastPasswordChange = std::time(nullptr); UInfo.userinfo.lastPasswordChange = std::time(nullptr);
UInfo.userinfo.changePassword = false; UInfo.userinfo.changePassword = false;
UInfo.userinfo.modified = std::time(nullptr);
StorageService()->UserDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo); StorageService()->UserDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo);
} }
@@ -468,6 +469,7 @@ namespace OpenWifi {
} }
UInfo.userinfo.lastPasswordChange = std::time(nullptr); UInfo.userinfo.lastPasswordChange = std::time(nullptr);
UInfo.userinfo.changePassword = false; UInfo.userinfo.changePassword = false;
UInfo.userinfo.modified = std::time(nullptr);
StorageService()->SubDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo); StorageService()->SubDB().UpdateUserInfo(AUTHENTICATION_SYSTEM, UInfo.userinfo.id,UInfo.userinfo);
} }
@@ -560,6 +562,7 @@ namespace OpenWifi {
A.id = MicroService::CreateUUID(); A.id = MicroService::CreateUUID();
A.created = std::time(nullptr); A.created = std::time(nullptr);
A.expires = A.created + 24*60*60; A.expires = A.created + 24*60*60;
A.userAction = true;
StorageService()->ActionLinksDB().CreateAction(A); StorageService()->ActionLinksDB().CreateAction(A);
UInfo.waitingForEmailCheck = true; UInfo.waitingForEmailCheck = true;
return true; return true;
@@ -573,6 +576,7 @@ namespace OpenWifi {
A.id = MicroService::CreateUUID(); A.id = MicroService::CreateUUID();
A.created = std::time(nullptr); A.created = std::time(nullptr);
A.expires = A.created + 24*60*60; A.expires = A.created + 24*60*60;
A.userAction = false;
StorageService()->ActionLinksDB().CreateAction(A); StorageService()->ActionLinksDB().CreateAction(A);
UInfo.waitingForEmailCheck = true; UInfo.waitingForEmailCheck = true;
return true; return true;

View File

@@ -77,7 +77,9 @@ namespace OpenWifi {
} }
SecurityObjects::UserInfo UInfo; SecurityObjects::UserInfo UInfo;
if(!StorageService()->UserDB().GetUserById(Link.userId,UInfo)) {
bool Found = Link.userAction ? StorageService()->UserDB().GetUserById(Link.userId,UInfo) : StorageService()->SubDB().GetUserById(Link.userId,UInfo);
if(!Found) {
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"}; Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"};
Types::StringPairVec FormVars{ {"UUID", Id}, Types::StringPairVec FormVars{ {"UUID", Id},
{"ERROR_TEXT", "This request does not contain a valid user ID. Please contact your system administrator."}}; {"ERROR_TEXT", "This request does not contain a valid user ID. Please contact your system administrator."}};
@@ -91,13 +93,20 @@ namespace OpenWifi {
return SendHTMLFileBack(FormFile,FormVars); return SendHTMLFileBack(FormFile,FormVars);
} }
if(!AuthService()->SetPassword(Password1,UInfo)) { bool GoodPassword = Link.userAction ? AuthService()->SetPassword(Password1,UInfo) : AuthService()->SetSubPassword(Password1,UInfo);
if(!GoodPassword) {
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"}; Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"};
Types::StringPairVec FormVars{ {"UUID", Id}, Types::StringPairVec FormVars{ {"UUID", Id},
{"ERROR_TEXT", "You cannot reuse one of your recent passwords."}}; {"ERROR_TEXT", "You cannot reuse one of your recent passwords."}};
return SendHTMLFileBack(FormFile,FormVars); return SendHTMLFileBack(FormFile,FormVars);
} }
StorageService()->UserDB().UpdateUserInfo(UInfo.email,Link.userId,UInfo);
UInfo.modified = std::time(nullptr);
if(Link.userAction)
StorageService()->UserDB().UpdateUserInfo(UInfo.email,Link.userId,UInfo);
else
StorageService()->SubDB().UpdateUserInfo(UInfo.email,Link.userId,UInfo);
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_success.html"}; Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_success.html"};
Types::StringPairVec FormVars{ {"UUID", Id}, Types::StringPairVec FormVars{ {"UUID", Id},
{"USERNAME", UInfo.email}, {"USERNAME", UInfo.email},
@@ -118,7 +127,8 @@ namespace OpenWifi {
} }
SecurityObjects::UserInfo UInfo; SecurityObjects::UserInfo UInfo;
if (!StorageService()->UserDB().GetUserById(Link.userId, UInfo)) { bool Found = Link.userAction ? StorageService()->UserDB().GetUserById(Link.userId,UInfo) : StorageService()->SubDB().GetUserById(Link.userId,UInfo);
if (!Found) {
Types::StringPairVec FormVars{{"UUID", Link.id}, Types::StringPairVec FormVars{{"UUID", Link.id},
{"ERROR_TEXT", "This does not appear to be a valid email verification link.."}}; {"ERROR_TEXT", "This does not appear to be a valid email verification link.."}};
Poco::File FormFile{Daemon()->AssetDir() + "/email_verification_error.html"}; Poco::File FormFile{Daemon()->AssetDir() + "/email_verification_error.html"};
@@ -130,7 +140,11 @@ namespace OpenWifi {
UInfo.validated = true; UInfo.validated = true;
UInfo.lastEmailCheck = std::time(nullptr); UInfo.lastEmailCheck = std::time(nullptr);
UInfo.validationDate = std::time(nullptr); UInfo.validationDate = std::time(nullptr);
StorageService()->UserDB().UpdateUserInfo(UInfo.email, Link.userId, UInfo); UInfo.modified = std::time(nullptr);
if(Link.userAction)
StorageService()->UserDB().UpdateUserInfo(UInfo.email, Link.userId, UInfo);
else
StorageService()->SubDB().UpdateUserInfo(UInfo.email, Link.userId, UInfo);
Types::StringPairVec FormVars{{"UUID", Link.id}, Types::StringPairVec FormVars{{"UUID", Link.id},
{"USERNAME", UInfo.email}, {"USERNAME", UInfo.email},
{"ACTION_LINK",MicroService::instance().GetUIURI()}}; {"ACTION_LINK",MicroService::instance().GetUIURI()}};

View File

@@ -84,6 +84,7 @@ namespace OpenWifi {
NewLink.userId = UInfo1.id; NewLink.userId = UInfo1.id;
NewLink.created = std::time(nullptr); NewLink.created = std::time(nullptr);
NewLink.expires = NewLink.created + (24*60*60); NewLink.expires = NewLink.created + (24*60*60);
NewLink.userAction = true;
StorageService()->ActionLinksDB().CreateAction(NewLink); StorageService()->ActionLinksDB().CreateAction(NewLink);
Poco::JSON::Object ReturnObj; Poco::JSON::Object ReturnObj;

View File

@@ -78,6 +78,7 @@ namespace OpenWifi {
NewLink.userId = UInfo1.id; NewLink.userId = UInfo1.id;
NewLink.created = std::time(nullptr); NewLink.created = std::time(nullptr);
NewLink.expires = NewLink.created + (24*60*60); NewLink.expires = NewLink.created + (24*60*60);
NewLink.userAction = false;
StorageService()->ActionLinksDB().CreateAction(NewLink); StorageService()->ActionLinksDB().CreateAction(NewLink);
Poco::JSON::Object ReturnObj; Poco::JSON::Object ReturnObj;

View File

@@ -498,6 +498,7 @@ namespace OpenWifi::SecurityObjects {
field_to_json(Obj,"expires",expires); field_to_json(Obj,"expires",expires);
field_to_json(Obj,"completed",completed); field_to_json(Obj,"completed",completed);
field_to_json(Obj,"canceled",canceled); field_to_json(Obj,"canceled",canceled);
field_to_json(Obj,"userAction",userAction);
} }
bool ActionLink::from_json(Poco::JSON::Object::Ptr &Obj) { bool ActionLink::from_json(Poco::JSON::Object::Ptr &Obj) {
@@ -514,6 +515,7 @@ namespace OpenWifi::SecurityObjects {
field_from_json(Obj,"expires",expires); field_from_json(Obj,"expires",expires);
field_from_json(Obj,"completed",completed); field_from_json(Obj,"completed",completed);
field_from_json(Obj,"canceled",canceled); field_from_json(Obj,"canceled",canceled);
field_from_json(Obj,"userAction",userAction);
return true; return true;
} catch(...) { } catch(...) {

View File

@@ -248,6 +248,7 @@ namespace OpenWifi {
uint64_t expires=0; uint64_t expires=0;
uint64_t completed=0; uint64_t completed=0;
uint64_t canceled=0; uint64_t canceled=0;
bool userAction=true;
void to_json(Poco::JSON::Object &Obj) const; void to_json(Poco::JSON::Object &Obj) const;
bool from_json(Poco::JSON::Object::Ptr &Obj); bool from_json(Poco::JSON::Object::Ptr &Obj);

View File

@@ -16,7 +16,8 @@
"created bigint," "created bigint,"
"expires bigint," "expires bigint,"
"completed bigint," "completed bigint,"
"canceled bigint" "canceled bigint,
userAction boolean"
*/ */
namespace OpenWifi { namespace OpenWifi {
@@ -32,7 +33,8 @@ namespace OpenWifi {
ORM::Field{"created", ORM::FieldType::FT_BIGINT}, ORM::Field{"created", ORM::FieldType::FT_BIGINT},
ORM::Field{"expires", ORM::FieldType::FT_BIGINT}, ORM::Field{"expires", ORM::FieldType::FT_BIGINT},
ORM::Field{"completed", ORM::FieldType::FT_BIGINT}, ORM::Field{"completed", ORM::FieldType::FT_BIGINT},
ORM::Field{"canceled", ORM::FieldType::FT_BIGINT} ORM::Field{"canceled", ORM::FieldType::FT_BIGINT},
ORM::Field{"userAction", ORM::FieldType::FT_BOOLEAN}
}; };
ActionLinkDB::ActionLinkDB(const std::string &Name, const std::string &ShortName, OpenWifi::DBType T, ActionLinkDB::ActionLinkDB(const std::string &Name, const std::string &ShortName, OpenWifi::DBType T,
@@ -40,6 +42,16 @@ namespace OpenWifi {
DB(T, Name.c_str(), ActionLinksDB_Fields,{}, P, L, ShortName.c_str()) { DB(T, Name.c_str(), ActionLinksDB_Fields,{}, P, L, ShortName.c_str()) {
} }
bool ActionLinkDB::Upgrade(uint32_t from, uint32_t &to) {
std::vector<std::string> Statements{
"alter table " + TableName_ + " add column userAction BOOLEAN default true;"
};
RunScript(Statements);
to = 1;
return true;
return true;
}
bool ActionLinkDB::CreateAction( SecurityObjects::ActionLink & A) { bool ActionLinkDB::CreateAction( SecurityObjects::ActionLink & A) {
return CreateRecord(A); return CreateRecord(A);
} }
@@ -105,6 +117,7 @@ template<> void ORM::DB<OpenWifi::ActionLinkRecordTuple,
U.expires = T.get<9>(); U.expires = T.get<9>();
U.completed = T.get<10>(); U.completed = T.get<10>();
U.canceled = T.get<11>(); U.canceled = T.get<11>();
U.userAction = T.get<12>();
} }
template<> void ORM::DB<OpenWifi::ActionLinkRecordTuple, template<> void ORM::DB<OpenWifi::ActionLinkRecordTuple,
@@ -121,4 +134,5 @@ template<> void ORM::DB<OpenWifi::ActionLinkRecordTuple,
T.set<9>(U.expires); T.set<9>(U.expires);
T.set<10>(U.completed); T.set<10>(U.completed);
T.set<11>(U.canceled); T.set<11>(U.canceled);
T.set<12>(U.userAction);
} }

View File

@@ -21,7 +21,8 @@ namespace OpenWifi {
uint64_t, // created uint64_t, // created
uint64_t, // expires uint64_t, // expires
uint64_t, // completed uint64_t, // completed
uint64_t // canceled uint64_t, // canceled
bool // userAction
> ActionLinkRecordTuple; > ActionLinkRecordTuple;
typedef std::vector <ActionLinkRecordTuple> ActionLinkRecordTupleList; typedef std::vector <ActionLinkRecordTuple> ActionLinkRecordTupleList;
@@ -38,6 +39,9 @@ namespace OpenWifi {
bool GetActions(std::vector<SecurityObjects::ActionLink> &Links, uint64_t Max=200); bool GetActions(std::vector<SecurityObjects::ActionLink> &Links, uint64_t Max=200);
void CleanOldActionLinks(); void CleanOldActionLinks();
inline uint32_t Version() override { return 1;}
bool Upgrade(uint32_t from, uint32_t &to) override;
private: private:
}; };