version 0.3.20
[fms.git] / src / http / pages / createidentitypage.cpp
1 #include "../../../include/http/pages/createidentitypage.h"\r
2 #include "../../../include/stringfunctions.h"\r
3 \r
4 #include <Poco/DateTime.h>\r
5 #include <Poco/DateTimeFormatter.h>\r
6 \r
7 #ifdef XMEM\r
8         #include <xmem.h>\r
9 #endif\r
10 \r
11 const std::string CreateIdentityPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
12 {\r
13         std::string content="";\r
14 \r
15         if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="create" && ValidateFormPassword(queryvars))\r
16         {\r
17                 SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublishTrustList,DateCreated) VALUES(?,'false',?);");\r
18                 std::string name="";\r
19                 Poco::DateTime date;\r
20 \r
21                 if(queryvars.find("name")!=queryvars.end())\r
22                 {\r
23                         name=(*queryvars.find("name")).second;\r
24                 }\r
25 \r
26                 st.Bind(0,name);\r
27                 st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
28                 st.Step();\r
29 \r
30                 // insert all identities not in trust list already\r
31                 m_db->Execute("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) SELECT LocalIdentityID,IdentityID FROM tblLocalIdentity,tblIdentity WHERE LocalIdentityID || '_' || IdentityID NOT IN (SELECT LocalIdentityID || '_' || IdentityID FROM tblIdentityTrust);");\r
32 \r
33                 content+="<h2>Created Identity</h2>";\r
34                 content+="You must have at least 1 local identity that has set explicit trust list trust for one or more peers who are publishing trust lists or you will not be able to learn about other identities.";\r
35         }\r
36         else\r
37         {\r
38                 content+="<h2>Create Identity</h2>";\r
39                 content+="<form name=\"frmcreateidentity\" method=\"POST\">";\r
40                 content+=CreateFormPassword();\r
41                 content+="<input type=\"hidden\" name=\"formaction\" value=\"create\">";\r
42                 content+="Name : <input type=\"text\" name=\"name\" maxlength=\"40\">";\r
43                 content+=" <input type=\"submit\" value=\"Create\">";\r
44                 content+="</form>";\r
45         }\r
46 \r
47         return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
48 }\r
49 \r
50 const bool CreateIdentityPage::WillHandleURI(const std::string &uri)\r
51 {\r
52         if(uri.find("createidentity.")!=std::string::npos)\r
53         {\r
54                 return true;\r
55         }\r
56         else\r
57         {\r
58                 return false;\r
59         }\r
60 }\r