CLEANUP: moved registration to seperate php file
authorArun Persaud <arun@nubati.net>
Sat, 28 Jul 2007 16:44:33 +0000 (09:44 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 28 Jul 2007 17:07:18 +0000 (10:07 -0700)
started cleanup on index.php. trying to move as much out of index.php
as possible to make it easier to read.

index.php
output.php
register.php [new file with mode: 0644]

index 8c34a2be61aa6aec92f6f83017b071c37e699421..40708f8359c3767cc30382dbae508a4f08ed1e5b 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1902,38 +1902,6 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
      DB_close();
      exit();
    }
-/* page for registration */
- else if(myisset("register") )
-   {
-     output_register();
-   }
-/* new user wants to register */
- else if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
-   {
-     $ok=1;
-     if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
-       {
-        echo "please chose another name<br />";
-        $ok=0;
-       }
-     if(DB_get_userid_by_email($_REQUEST["Remail"]))
-       {
-        echo "this email address is already used ?!<br />";
-        $ok=0;
-       }
-     if($ok)
-       {
-        $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
-                       ",".DB_quote_smart($_REQUEST["Remail"]).
-                       ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
-                       ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)"); 
-        
-        if($r)
-          echo " added you to the database";
-        else
-          echo " something went wrong, couldn't add you to the database, please contact $ADMIN_NAME at $ADMIN_EMAIL.";
-       }
-   }
 /* default login page */
  else
    { 
index 32c81089a745105003d390e5dd30e97f27540471..845281563615800795606c6e54cbd79de07c735b 100644 (file)
@@ -37,43 +37,6 @@ function output_user_settings($email,$password)
   return;
 }
 
-function output_register()
-{
-  echo "IMPORTANT: passwords are going over the net as clear text, so pick an easy password. No need to pick anything complicated here ;)<br /><br />";
-  echo "TODO: figure out a better way to handle passwords <br />\n";
-  ?>
-        <form action="index.php" method="post">
-          <fieldset>
-            <legend>Register</legend>
-             <table>
-              <tr>
-               <td><label for="Rfullname">Full name:</label></td>
-              <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
-              </tr><tr>
-               <td><label for="Remail">Email:</label></td>
-              <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
-              </tr><tr>
-              <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
-               <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
-              </tr><tr>
-              <td><label for="Rtimezone">Timezone:</label></td>
-               <td>
-                 <select id="Rtimezone" name="Rtimezone" size="1">
-                     <option value="1">Berlin</option>
-                     <option value="-8">Berkeley</option>
-                     <option value="13">Wellington</option>
-                 </select>
-                (If your timezone is not listed, just select whatever you want and email the admin your correct time zone.)
-              </td>
-              </tr><tr>
-               <td colspan="2"> <input type="submit" value="register" /></td>
-             </table>
-          </fieldset>
-        </form>
-<?php
-  return;
-}                                         
-
 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
 {
   global $RULES;
@@ -309,7 +272,7 @@ function output_home_page($pre,$game,$done,$avgtime)
       echo "$done games have been completed on this server. Average time of a game: $avgtime days</p>";
 ?>
 
-    <p> Please <a href="index.php?register">register</a>, in case you haven't done that yet  <br />
+    <p> Please <a href="register.php">register</a>, in case you haven't done that yet  <br />
         or login with you email-address or name and password here:
     </p>
         <form action="index.php" method="post">
diff --git a/register.php b/register.php
new file mode 100644 (file)
index 0000000..827e77e
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+error_reporting(E_ALL);
+
+include_once("config.php");      
+include_once("output.php");      /* html output only */
+include_once("db.php");          /* database only */
+include_once("functions.php");   /* the rest */
+
+config_check();
+
+if(DB_open()<0)
+  {
+    output_header();
+    echo "Database error, can't connect... Please wait a while and try again. ".
+      "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
+    output_footer(); 
+    exit(); 
+  }
+
+
+/* done major error checking, output header of HTML page */
+output_header();
+
+/* new user wants to register */
+if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
+  {
+    $ok=1;
+    if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
+      {
+       echo "please chose another name<br />";
+       $ok=0;
+      }
+    if(DB_get_userid_by_email($_REQUEST["Remail"]))
+      {
+       echo "this email address is already used ?!<br />";
+       $ok=0;
+      }
+    if($ok)
+      {
+       $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
+                      ",".DB_quote_smart($_REQUEST["Remail"]).
+                      ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
+                      ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)"); 
+       
+       if($r)
+         echo " Welcome to e-DoKo, you are now registered, please visit the".
+           " <a href=\"$host\">homepage</a> to continue.";
+       else
+         echo " something went wrong, couldn't add you to the database, please contact $ADMIN_NAME at $ADMIN_EMAIL.";
+      }
+   }
+/* page for registration */
+ else
+   {
+     echo "IMPORTANT: passwords are going over the net as clear text, so pick an easy password. No need to pick anything complicated here ;)<br /><br />";
+     ?>
+        <form action="register.php" method="post">
+          <fieldset>
+            <legend>Register</legend>
+             <table>
+              <tr>
+               <td><label for="Rfullname">Full name:</label></td>
+              <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
+              </tr><tr>
+               <td><label for="Remail">Email:</label></td>
+              <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
+              </tr><tr>
+              <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
+               <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
+              </tr><tr>
+              <td><label for="Rtimezone">Timezone:</label></td>
+               <td>
+                 <select id="Rtimezone" name="Rtimezone" size="1">
+                     <option value="1">Berlin</option>
+                     <option value="-8">Berkeley</option>
+                     <option value="13">Wellington</option>
+                 </select>
+                (If your timezone is not listed, just select whatever you want and email the admin your correct time zone.)
+              </td>
+              </tr><tr>
+               <td colspan="2"> <input type="submit" value="register" /></td>
+             </table>
+          </fieldset>
+        </form>
+<?php
+   }
+
+output_footer();
+
+DB_close();
+
+/*
+ *Local Variables: 
+ *mode: php
+ *mode: hs-minor
+ *End:
+ */
+?>