Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

AccountForm.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 //#include <stdio.h> 00024 00025 #include "IWeb.h" 00026 #include <libibank.h> 00027 #include "AccountForm.h" 00028 00029 00030 00031 00032 AccountForm::AccountForm(Web *w) : BaseForm(w, "AccountForm") 00033 ,m_bPass(false) 00034 ,m_bEmail(false) 00035 ,m_bExists(false) 00036 ,m_bName(false) 00037 { 00038 } 00039 00040 00041 AccountForm::~AccountForm() 00042 { 00043 } 00044 00045 00046 void AccountForm::Process() 00047 { 00048 IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00049 Database& db = pWeb -> GetDatabase(); 00050 Query q(db); 00051 char action[200]; 00052 if (0) 00053 { 00054 std::string form_name = GetFormName(); 00055 std::string action = GetForm() -> getvalue(form_name); 00056 printf("%s: %s<br>",form_name.c_str(),action.c_str()); 00057 } 00058 // <input type="submit" name="AccountForm" value="action" ... 00059 if (!GetForm() -> getvalue( (char *)GetFormName().c_str(), action, 200) || !*action) 00060 { 00061 return; 00062 } 00063 char sql[1000]; 00064 if (!strcmp(action," Login ")) 00065 { 00066 sprintf(sql,"select * from account where email='%s' and secret='%s'", 00067 q.safestr(GetForm() -> getvalue("email")).c_str(), 00068 q.safestr(GetForm() -> getvalue("secret")).c_str() ); 00069 db::Account account(&db, sql); 00070 if (account.num) 00071 { 00072 long valid = random(); 00073 db::Valid x(&db); 00074 x.account = account.num; 00075 x.valid = valid; 00076 x.save(); 00077 pWeb -> SetUsernum( account.num ); 00078 pWeb -> SetValid( valid ); 00079 pWeb -> SetPage( 3 ); // Forums list 00080 } 00081 } 00082 else 00083 if (!strcmp(action," Register ")) 00084 { 00085 std::string email = GetForm() -> getvalue("new_email"); 00086 m_email = email; 00087 m_name = GetForm() -> getvalue("namn"); 00088 m_show = GetForm() -> getvalue("show_email"); 00089 if (!valid_email(email)) 00090 { 00091 m_bEmail = true; 00092 return; 00093 } 00094 bool alnum = false; 00095 for (size_t i = 0; i < m_name.size(); i++) 00096 { 00097 if (isalnum(m_name[i])) 00098 { 00099 alnum = true; 00100 } 00101 else 00102 if (m_name[i] != ' ') 00103 { 00104 m_bName = true; 00105 return; 00106 } 00107 } 00108 if (!alnum) 00109 { 00110 m_bName = true; 00111 return; 00112 } 00113 std::string secret = GetForm() -> getvalue("new_secret"); 00114 if (secret.size() < 4 || secret != GetForm() -> getvalue("new_secret2")) 00115 { 00116 m_bPass = true; 00117 return; 00118 } 00119 sprintf(sql,"select * from account where email='%s'",q.safestr(email).c_str()); 00120 db::Account account(&db, sql); 00121 if (account.num) 00122 { 00123 m_bExists = true; 00124 return; 00125 } 00126 account.email = email; 00127 account.secret = secret; 00128 account.name = m_name; 00129 account.show_email = atoi(m_show.c_str()); 00130 account.save(); 00131 // create valid 00132 if (account.num) 00133 { 00134 long valid = random(); 00135 db::Valid x(&db); 00136 x.account = account.num; 00137 x.valid = valid; 00138 x.save(); 00139 pWeb -> SetUsernum( account.num ); 00140 pWeb -> SetValid( valid ); 00141 pWeb -> SetPage( 3 ); // Forums list 00142 } 00143 } 00144 } 00145 00146 00147 void AccountForm::Display(long) 00148 { 00149 // IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00150 00151 printf("<form action=\"%s\" method=post>",GetCgiName().c_str()); 00152 fflush(stdout); 00153 printf("<h3>Login</h3>"); 00154 printf("<table cellpadding=\"0\" cellspacing=\"0\" class=login>"); 00155 printf("<tr><td class=login>"); 00156 printf("Email<br>"); 00157 printf("<input type=text size=40 name=email><br>"); 00158 printf("</td></tr><tr><td class=login>"); 00159 printf("Password<br>"); 00160 printf("<input type=password name=secret><br>"); 00161 printf("</td></tr><tr><td class=login align=center>"); 00162 printf("<input type=submit name=\"%s\" value=\" Login \"><br>",GetFormName().c_str()); 00163 printf("</td></tr></table>"); 00164 00165 printf("<h3>Register</h3>"); 00166 printf("<table cellpadding=\"0\" cellspacing=\"0\" class=login>"); 00167 printf("<tr><td class=login>"); 00168 if (m_bEmail) 00169 printf("<font class=error size=\"+2\">Invalid email address</font><br>"); 00170 if (m_bExists) 00171 printf("<font class=error size=\"+2\">Email address already registrered</font><br>"); 00172 printf("Your email (used for login)<br>"); 00173 printf("<input type=text size=40 name=new_email value=\"%s\"><br>",m_email.c_str()); 00174 printf("</td></tr><tr><td class=login>"); 00175 if (m_bName) 00176 printf("<font class=error size=\"+2\">Invalid name</font><br>"); 00177 printf("Display name (only letters / digits please)<br>"); 00178 printf("<input type=text size=40 name=namn value=\"%s\"><br>",m_name.c_str()); 00179 printf("</td></tr><tr><td class=login>"); 00180 printf("<input type=checkbox name=show_email value=1%s> Show email address when posting<br>",m_show.size() ? " CHECKED" : ""); 00181 printf("</td></tr><tr><td class=login>"); 00182 if (m_bPass) 00183 printf("<font class=error size=\"+2\">Bad password</font><br>"); 00184 printf("Password (at least four characters long)<br>"); 00185 printf("<input type=password name=new_secret><br>"); 00186 printf("Please repeat password<br>"); 00187 printf("<input type=password name=new_secret2><br>"); 00188 printf("</td></tr><tr><td class=login align=center>"); 00189 printf("<input type=submit name=\"%s\" value=\" Register \"><br>",GetFormName().c_str()); 00190 printf("</td></tr></table>"); 00191 00192 printf("</form>"); 00193 } 00194 00195

Generated on Sat Feb 12 00:14:56 2005 for IBank by doxygen 1.3.7