Updated init script.
[dtbartle/bnbt.git] / tracker_signup.cpp
1 /***\r
2 *\r
3 * BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
4 * Copyright (C) 2003-2004 Trevor Hogan\r
5 *\r
6 * CBTT variations (C) 2003-2005 Harold Feit\r
7 *\r
8 * This library is free software; you can redistribute it and/or\r
9 * modify it under the terms of the GNU Lesser General Public\r
10 * License as published by the Free Software Foundation; either\r
11 * version 2.1 of the License, or (at your option) any later version.\r
12 *\r
13 * This library is distributed in the hope that it will be useful,\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
16 * Lesser General Public License for more details.\r
17 *\r
18 * You should have received a copy of the GNU Lesser General Public\r
19 * License along with this library; if not, write to the Free Software\r
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
21 *\r
22 ***/\r
23 \r
24 #include "bnbt.h"\r
25 #include "atom.h"\r
26 #include "tracker.h"\r
27 #include "util.h"\r
28 \r
29 void CTracker :: serverResponseSignup( struct request_t *pRequest, struct response_t *pResponse, user_t user )\r
30 {\r
31         pResponse->strCode = "200 OK";\r
32 \r
33         pResponse->mapHeaders.insert( pair<string, string>( "Content-Type", string( "text/html; charset=" ) + gstrCharSet ) );\r
34 \r
35         pResponse->strContent += "<html>\n";\r
36         pResponse->strContent += "<head>\n";\r
37         if ( !gstrTrackerTitle.empty( ) )\r
38                 pResponse->strContent += "<title>" + gstrTrackerTitle + " - Tracker Sign Up</title>\n";\r
39         else\r
40                 pResponse->strContent += "<title>BNBT Tracker Sign Up</title>\n";\r
41 \r
42         if( !gstrStyle.empty( ) )\r
43                 pResponse->strContent += "<link rel=stylesheet type=\"text/css\" href=\"" + gstrStyle + "\">\n";\r
44 \r
45         pResponse->strContent += "</head>\n";\r
46         pResponse->strContent += "<body>\n";\r
47 \r
48         // The Trinity Edition - Addition Begins\r
49         // The following adds an RTT link to the SIGNUP PAGE\r
50 \r
51         pResponse->strContent += "<p><a href=\"/index.html\">Return to Tracker</a></p>\n";\r
52 \r
53         // ------------------------------------------------- End of Addition\r
54 \r
55         if( !m_bDisableLogon )\r
56         {\r
57                 if( user.strLogin.empty( ) )\r
58                         pResponse->strContent += "<p class=\"login1_index\">You are not logged in. Click <a href=\"/login.html\">here</a> to login.</p>\n";\r
59                 else\r
60                         pResponse->strContent += "<p class=\"login2_index\">You are logged in as <span class=\"username\">" + UTIL_RemoveHTML( user.strLogin ) + "</span>. Click <a href=\"/login.html?logout=1\">here</a> to logout.</p>\n";\r
61         }\r
62 \r
63         if ( !gstrTrackerTitle.empty( ) )\r
64                 pResponse->strContent += "<h3>" + gstrTrackerTitle + " - Tracker Sign Up</h3>\n";\r
65         else\r
66                 pResponse->strContent += "<h3>BNBT Tracker Sign Up</h3>\n";\r
67 \r
68         if( user.iAccess & ACCESS_SIGNUP )\r
69         {\r
70                 if( pRequest->mapParams.find( "us_login" ) != pRequest->mapParams.end( ) &&\r
71                         pRequest->mapParams.find( "us_password" ) != pRequest->mapParams.end( ) &&\r
72                         pRequest->mapParams.find( "us_password_verify" ) != pRequest->mapParams.end( ) &&\r
73                         pRequest->mapParams.find( "us_email" ) != pRequest->mapParams.end( ) )\r
74                 {\r
75                         string strLogin = pRequest->mapParams["us_login"];\r
76                         string strPass = pRequest->mapParams["us_password"];\r
77                         string strPass2 = pRequest->mapParams["us_password_verify"];\r
78                         string strMail = pRequest->mapParams["us_email"];\r
79 \r
80                         if( strLogin.empty( ) || strPass.empty( ) || strPass2.empty( ) || strMail.empty( ) )\r
81                         {\r
82                                 pResponse->strContent += "<p>Unable to signup. You must fill in all the fields. Click <a href=\"/signup.html\">here</a> to return to the signup page.</p>\n";\r
83                                 pResponse->strContent += "</body>\n";\r
84                                 pResponse->strContent += "</html>\n";\r
85 \r
86                                 return;\r
87                         }\r
88                         else\r
89                         {\r
90                                 if( strLogin[0] == ' ' || strLogin[strLogin.size( ) - 1] == ' ' || strLogin.size( ) > (unsigned int)m_iNameLength )\r
91                                 {\r
92                                         pResponse->strContent += "<p>Unable to signup. Your name must be less than " + CAtomInt( m_iNameLength ).toString( ) + " characters long and it must not start or end with spaces. Click <a href=\"/signup.html\">here</a> to return to the signup page.</p>\n";\r
93                                         pResponse->strContent += "</body>\n";\r
94                                         pResponse->strContent += "</html>\n";\r
95 \r
96                                         return;\r
97                                 }\r
98 \r
99                                 if( strMail.find( "@" ) == string :: npos || strMail.find( "." ) == string :: npos )\r
100                                 {\r
101                                         pResponse->strContent += "<p>Unable to signup. Your e-mail address is invalid. Click <a href=\"/signup.html\">here</a> to return to the signup page.</p>\n";\r
102                                         pResponse->strContent += "</body>\n";\r
103                                         pResponse->strContent += "</html>\n";\r
104 \r
105                                         return;\r
106                                 }\r
107 \r
108                                 if( strPass == strPass2 )\r
109                                 {\r
110                                         if( m_pUsers->getItem( strLogin ) )\r
111                                         {\r
112                                                 pResponse->strContent += "<p>Unable to signup. The user \"" + UTIL_RemoveHTML( strLogin ) + "\" already exists. Click <a href=\"/signup.html\">here</a> to return to the signup page.</p>\n";\r
113                                                 pResponse->strContent += "</body>\n";\r
114                                                 pResponse->strContent += "</html>\n";\r
115 \r
116                                                 return;\r
117                                         }\r
118                                         else\r
119                                         {\r
120                                                 addUser( strLogin, strPass, m_iMemberAccess, strMail );\r
121 \r
122                                                 pResponse->strContent += "<p>Thanks! You've successfully signed up! Click <a href=\"/login.html\">here</a> to login.</p>\n";\r
123                                                 pResponse->strContent += "</body>\n";\r
124                                                 pResponse->strContent += "</html>\n";\r
125 \r
126                                                 return;\r
127                                         }\r
128                                 }\r
129                                 else\r
130                                 {\r
131                                         pResponse->strContent += "<p>Unable to signup. The passwords did not match. Click <a href=\"/signup.html\">here</a> to return to the signup page.</p>\n";\r
132                                         pResponse->strContent += "</body>\n";\r
133                                         pResponse->strContent += "</html>\n";\r
134 \r
135                                         return;\r
136                                 }\r
137                         }\r
138                 }\r
139 \r
140                 pResponse->strContent += "<form method=\"get\" action=\"/signup.html\">\n";\r
141                 pResponse->strContent += "<p><strong>Signup</strong></p>\n";\r
142                 pResponse->strContent += "<ul>\n";\r
143                 pResponse->strContent += "<li>Names must be less than " + CAtomInt( m_iNameLength ).toString( ) + " characters long</li>\n";\r
144                 pResponse->strContent += "<li>Names are case sensitive</li>\n";\r
145                 pResponse->strContent += "<li>No HTML</li>\n";\r
146                 pResponse->strContent += "</ul>\n";\r
147                 pResponse->strContent += "<input name=\"us_login\" type=text size=24 maxlength=" + CAtomInt( m_iNameLength ).toString( ) + "> Login<br><br>\n";\r
148                 pResponse->strContent += "<input name=\"us_password\" type=password size=20> Password<br>\n";\r
149                 pResponse->strContent += "<input name=\"us_password_verify\" type=password size=20> Verify Password<br><br>\n";\r
150                 pResponse->strContent += "<input name=\"us_email\" type=text size=40> E-Mail<br><br>\n";\r
151                 pResponse->strContent += "<input type=submit value=\"Signup\">\n";\r
152                 pResponse->strContent += "</form>\n";\r
153         }\r
154         else\r
155                 pResponse->strContent += "<p class=\"denied\">You are not authorized to view this page.</p>\n";\r
156 \r
157         pResponse->strContent += "</body>\n";\r
158         pResponse->strContent += "</html>\n";\r
159 }\r