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

AccountForm Class Reference

#include <AccountForm.h>

Inheritance diagram for AccountForm:

Inheritance graph
[legend]
Collaboration diagram for AccountForm:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AccountForm (Web *)
 ~AccountForm ()
void Process ()
void Display (long)
void Select (const std::string &)
void List ()

Private Attributes

bool m_bPass
bool m_bEmail
bool m_bExists
bool m_bName
std::string m_email
std::string m_name
std::string m_show

Detailed Description

File ......... AccountForm.h Published .... 2004-07-09 Author ....... grymse@alhem.net

Definition at line 31 of file AccountForm.h.


Constructor & Destructor Documentation

AccountForm::AccountForm Web *  w  ) 
 

File ......... AccountForm.cpp Published .... 2004-07-09 Author ....... grymse@alhem.net

Definition at line 32 of file AccountForm.cpp.

References AccountForm().

Referenced by AccountForm().

00032 : BaseForm(w, "AccountForm") 00033 ,m_bPass(false) 00034 ,m_bEmail(false) 00035 ,m_bExists(false) 00036 ,m_bName(false) 00037 { 00038 }

AccountForm::~AccountForm  ) 
 

Definition at line 41 of file AccountForm.cpp.

00042 { 00043 }


Member Function Documentation

void AccountForm::Display long   ) 
 

Definition at line 147 of file AccountForm.cpp.

References Display(), m_bEmail, m_bExists, m_bName, m_bPass, m_email, m_name, and m_show.

Referenced by Display(), and IWeb::GenerateDocument().

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 }

void AccountForm::List  )  [inline]
 

Definition at line 40 of file AccountForm.h.

00040 {}

void AccountForm::Process  ) 
 

Definition at line 46 of file AccountForm.cpp.

References m_bEmail, m_bExists, m_bName, m_bPass, m_email, m_name, and m_show.

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 }

void AccountForm::Select const std::string &   )  [inline]
 

Definition at line 39 of file AccountForm.h.

References Select().

Referenced by Select().

00039 {}


Member Data Documentation

bool AccountForm::m_bEmail [private]
 

Definition at line 44 of file AccountForm.h.

Referenced by Display(), and Process().

bool AccountForm::m_bExists [private]
 

Definition at line 45 of file AccountForm.h.

Referenced by Display(), and Process().

bool AccountForm::m_bName [private]
 

Definition at line 46 of file AccountForm.h.

Referenced by Display(), and Process().

bool AccountForm::m_bPass [private]
 

Definition at line 43 of file AccountForm.h.

Referenced by Display(), and Process().

std::string AccountForm::m_email [private]
 

Definition at line 47 of file AccountForm.h.

Referenced by Display(), and Process().

std::string AccountForm::m_name [private]
 

Definition at line 48 of file AccountForm.h.

Referenced by Display(), and Process().

std::string AccountForm::m_show [private]
 

Definition at line 49 of file AccountForm.h.

Referenced by Display(), and Process().


The documentation for this class was generated from the following files:
Generated on Sat Feb 12 00:14:57 2005 for IBank by doxygen 1.3.7