X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Fannounceidentitypage.cpp;h=7858d880c992fd20aa231e248255b5a7872a49f4;hb=fcb124f8d6d3f5678e82049fb8e5e23c8cfaec6d;hp=710904c274b9f61ec2b6bb98c77c1613120fd007;hpb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;p=fms.git diff --git a/src/http/pages/announceidentitypage.cpp b/src/http/pages/announceidentitypage.cpp index 710904c..7858d88 100644 --- a/src/http/pages/announceidentitypage.cpp +++ b/src/http/pages/announceidentitypage.cpp @@ -1,6 +1,9 @@ #include "../../../include/http/pages/announceidentitypage.h" #include "../../../include/stringfunctions.h" -#include "../../../include/datetime.h" +#include "../../../include/global.h" + +#include +#include #ifdef XMEM #include @@ -23,7 +26,7 @@ const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::s st.ResultText(1,name); st.ResultText(2,pubkey); - rval+=""; + rval+=""; st.Step(); } rval+=""; @@ -32,7 +35,7 @@ const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::s const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, const std::map &queryvars) { - DateTime date; + Poco::DateTime date; std::string content; int shown=0; std::string countstr=""; @@ -40,8 +43,10 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, std::string lastid=""; std::string thisid=""; std::string day=""; + int requestindex=0; + bool willshow=false; - if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce") + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce" && ValidateFormPassword(queryvars)) { SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblIdentityIntroductionInserts(LocalIdentityID,Day,UUID,Solution) VALUES(?,?,?,?);"); std::string localidentityidstr=""; @@ -76,19 +81,17 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, content+="

Announce Identity

"; content+="
"; + content+=CreateFormPassword(); content+=""; content+=""; content+=""; - content+=""; + content+=""; content+=""; - //TODO if we are already inserting a solution for an identity - we shouldn't select any puzzles that are older than the one we are inserting - - date.SetToGMTime(); - date.Add(0,0,0,-1); - SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,IdentityID FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='"+date.Format("%Y-%m-%d")+"' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;"); + date-=Poco::Timespan(1,0,0,0,0); + SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,IdentityID,RequestIndex FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;"); st.Step(); if(st.RowReturned()==false) @@ -101,8 +104,25 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, st.ResultText(0,uuid); st.ResultText(1,day); st.ResultText(2,thisid); + st.ResultInt(3,requestindex); + + // if we are already inserting a solution for an identity - we shouldn't show any puzzles that are older than the one we are inserting + // get the last index # we are inserting this day from this identity + // if the index here is greater than the index in the st statement, we will skip this puzzle because we are already inserting a puzzle with a greater index + willshow=true; + SQLite3DB::Statement st2=m_db->Prepare("SELECT MAX(RequestIndex) FROM tblIdentityIntroductionInserts INNER JOIN tblIntroductionPuzzleRequests ON tblIdentityIntroductionInserts.UUID=tblIntroductionPuzzleRequests.UUID WHERE tblIdentityIntroductionInserts.Day=? AND tblIdentityIntroductionInserts.UUID IN (SELECT UUID FROM tblIntroductionPuzzleRequests WHERE IdentityID=? AND Day=?) GROUP BY tblIdentityIntroductionInserts.Day;"); + st2.Step(); + if(st2.RowReturned()==true) + { + int index=0; + st2.ResultInt(0,index); + if(index>=requestindex) + { + willshow=false; + } + } - if(thisid!=lastid) + if(willshow && thisid!=lastid) { StringFunctions::Convert(shown,countstr); if(shown>0 && shown%4==0) @@ -115,7 +135,7 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, content+=""; content+=""; content+="\r\n"; - thisid=lastid; + lastid=thisid; shown++; } @@ -126,7 +146,7 @@ const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, content+="
Select Identity : "; content+=CreateLocalIdentityDropDown("localidentityid",""); content+="
Type the answers of a few puzzles
Type the answers of a few puzzles. The puzzles are case sensitive. Getting announced will take some time. DO NOT continuously solve captchas. Solve 30 at most, wait a day, and if your identity has not been announced, repeat until it is.
"; content+="
"; - return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); + return StringFunctions::Replace(m_template,"[CONTENT]",content); } const bool AnnounceIdentityPage::WillHandleURI(const std::string &uri)