Fixing ActionLinks

This commit is contained in:
stephb9959
2021-11-09 17:06:30 -08:00
parent 96f215b3c2
commit 2eae6cc73c
4 changed files with 23 additions and 8 deletions

2
build
View File

@@ -1 +1 @@
17
19

View File

@@ -55,11 +55,17 @@ namespace OpenWifi {
auto Password1 = Form.get("password1","bla");
auto Password2 = Form.get("password1","blu");
auto Id = Form.get("id","");
auto Now = std::time(nullptr);
SecurityObjects::ActionLink Link;
if(!StorageService()->GetActionLink(Id,Link))
return DoReturnA404();
if(Now > Link.expires) {
StorageService()->CancelAction(Id);
return DoReturnA404();
}
if(Password1!=Password2 || !AuthService()->ValidatePassword(Password2) || !AuthService()->ValidatePassword(Password1)) {
Poco::File FormFile{ Daemon()->AssetDir() + "/password_reset_error.html"};
Types::StringPairVec FormVars{ {"UUID", Id},
@@ -96,6 +102,7 @@ namespace OpenWifi {
Types::StringPairVec FormVars{ {"UUID", Id},
{"USERNAME", UInfo.email},
{"ACTION_LINK",MicroService::instance().GetUIURI()}};
StorageService()->CompleteAction(Id);
SendHTMLFileBack(FormFile,FormVars);
} else {
DoReturnA404();
@@ -103,8 +110,14 @@ namespace OpenWifi {
}
void RESTAPI_action_links::DoEmailVerification(SecurityObjects::ActionLink &Link) {
SecurityObjects::UserInfo UInfo;
auto Now = std::time(nullptr);
if(Now > Link.expires) {
StorageService()->CancelAction(Link.id);
return DoReturnA404();
}
SecurityObjects::UserInfo UInfo;
Logger_.information(Poco::format("EMAIL-VERIFICATION(%s): For ID=%s", Request->clientAddress().toString(), Link.userId));
if (!StorageService()->GetUserByEmail(Link.userId, UInfo)) {
Types::StringPairVec FormVars{{"UUID", Link.id},
@@ -122,6 +135,7 @@ namespace OpenWifi {
{"USERNAME", UInfo.email},
{"ACTION_LINK",MicroService::instance().GetUIURI()}};
Poco::File FormFile{Daemon()->AssetDir() + "/email_verification_success.html"};
StorageService()->CompleteAction(Link.id);
SendHTMLFileBack(FormFile, FormVars);
}

View File

@@ -1726,7 +1726,7 @@ namespace OpenWifi {
Response->set("Cache-Control", "private");
Response->set("Pragma", "private");
Response->set("Expires", "Mon, 26 Jul 2027 05:00:00 GMT");
Response->set("Content-Length", std::to_string(File.getSize()));
Response->setContentLength(File.getSize());
AddCORS();
Response->sendFile(File.path(),"application/octet-stream");
}
@@ -1766,7 +1766,7 @@ namespace OpenWifi {
Response->set("Expires", "Mon, 26 Jul 2027 05:00:00 GMT");
std::string FormContent = Utils::LoadFile(File.path());
Utils::ReplaceVariables(FormContent, FormVars);
Response->set("Content-Length", std::to_string(FormContent.size()));
Response->setContentLength(FormContent.size());
AddCORS();
Response->setChunkedTransferEncoding(true);
Response->setContentType("text/html");
@@ -3275,7 +3275,8 @@ namespace OpenWifi {
auto InsertResult = CertNames.insert(CertFileName);
if(InsertResult.second) {
Poco::JSON::Object Inner;
Inner.set("filename", CertFileName);
Poco::Path F(CertFileName);
Inner.set("filename", F.getFileName());
Poco::Crypto::X509Certificate C(CertFileName);
auto ExpiresOn = C.expiresOn();
Inner.set("expiresOn",ExpiresOn.timestamp().epochTime());

View File

@@ -69,9 +69,9 @@ namespace OpenWifi {
ActionLinkRecordList ARL;
std::string St2{
"SELECT " + AllActionLinksFieldsForSelect + " From ActionLinks where sent=0 and canceled=0"};
Select << ConvertParams(St2),
std::string S{
"SELECT " + AllActionLinksFieldsForSelect + " From ActionLinks where sent=0 and canceled=0 and completed=0"};
Select << ConvertParams(S),
Poco::Data::Keywords::into(ARL);
Select.execute();