made my star image a bit nicer
authorpaulr <me@pjr.cc>
Sun, 6 Nov 2011 16:05:57 +0000 (03:05 +1100)
committerpaulr <me@pjr.cc>
Sun, 6 Nov 2011 16:05:57 +0000 (03:05 +1100)
added the captcha plugin, which actually depends on
securimage/phpcaptcha from http://www.phpcaptcha.org/ - works quite
well, and this way i dont have to carry the phpcaptcha code with my
source tree.

added the capture bits to the reigstration page, but registration page
itself isnt functional

gwvplib/gwvpauth.php
gwvplib/gwvpemail.php [new file with mode: 0644]
gwvplib/gwvplib.php
gwvplib/gwvpuseradmin.php
gwvplib/plugins/captcha_plugin.php [new file with mode: 0644]
www/images/star.jpg

index f7e036d..ad42b2b 100644 (file)
@@ -9,10 +9,15 @@ function gwvp_AuthCallMe()
        session_start();
 
        if(isset($_REQUEST["q"])) {
-               $query = $_REQUEST["q"];
-               if($query == "login") return "gwvp_AuthHandleLogin";
-               if($query == "logout") return "gwvp_AuthHandleLogout";
-               if($query == "register") return "gwvp_RegistrationCall";
+               $query = explode("/", $_REQUEST["q"]);
+               if($query[0] == "login") return "gwvp_AuthHandleLogin";
+               if($query[0] == "logout") return "gwvp_AuthHandleLogout";
+               if($query[0] == "register") {
+                       if(isset($query[1])) {
+                               return "qwvp_attemptRegistration";
+                       }
+                       return "gwvp_RegistrationCall";
+               }
        }
        $login = gwvp_isLoggedIn();
        
@@ -134,13 +139,24 @@ function gwvp_AuthHandleLogin()
 
 function gwvp_RegistrationPageBody()
 {
+       global $BASE_URL;
+       
+       // TODO: registration page needs to be prettier - mostly the image for the captcha
+       
        ?>
-<form method="post">
+<form method="post" action="<?php echo $BASE_URL?>/register/try">
        <table>
                <tr>
                        <td>Name</td>
                        <td><input name="name" type="text"></td>
                        <td>Your Full Name</td>
+                       <td rowspan="4">
+                               <?php if(gwvp_haveCaptcha()) {?>
+                               <img id="captcha" src="<?php echo $BASE_URL?>/securimage/" alt="CAPTCHA Image" /><br>
+                               <input type="text" name="captcha_code" size="10" maxlength="6" />
+                               <a href="#" onclick="document.getElementById('captcha').src = '<?php echo $BASE_URL?>/securimage/' + Math.random(); return false">[ Different Image ]</a>
+                               <?php } ?>
+                       </td>
                </tr>
                <tr>
                        <td>Email</td>
@@ -152,6 +168,8 @@ function gwvp_RegistrationPageBody()
                        <td><input name="username" type="text"></td>
                        <td>The Name Used to Refer to you on the site</td>
                </tr>
+               
+               
                <tr>
                        <td><input type="submit" name="register" value="Register"></td>
                </tr>
@@ -160,6 +178,24 @@ function gwvp_RegistrationPageBody()
        <?php
 }
 
+function qwvp_attemptRegistration()
+{
+       if(gwvp_haveCaptcha()) {
+               $securimage = new Securimage();
+               if ($securimage->check($_POST['captcha_code']) == false) {
+                 // the code was incorrect
+                 // you should handle the error so that the form processor doesn't continue
+               
+                 // or you can use the following code if there is no validation or you do not know how
+                 echo "The security code entered was incorrect.<br /><br />";
+                 echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
+               } else {
+                       echo "code was right";
+               }
+               
+       }
+}
+
 function gwvp_checkBasicAuthLogin()
 {
        $user = false;
diff --git a/gwvplib/gwvpemail.php b/gwvplib/gwvpemail.php
new file mode 100644 (file)
index 0000000..6e6a17b
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+
+function gwvp_sendValidationEmail()
+{
+       // TODO: code this 
+}
+
+?>
\ No newline at end of file
index 24b2d77..d70dc3f 100644 (file)
@@ -11,6 +11,7 @@ require_once("gwvpdatabase.php");
 require_once("gwvpconfig.php");
 require_once("gwvpgitcontrol.php");
 require_once("gwvpinputcheck.php");
+require_once("gwvpemail.php");
 
 // this is loaded second last
 require_once("gwvppluginloader.php");
index 1d3e83d..7db0c8d 100644 (file)
@@ -55,6 +55,7 @@ function gwvp_AddUserPage()
        $pass2 = $_REQUEST["pass2"];
        $username = $_REQUEST["username"];
        $desc = $_REQUEST["desc"];
+       $sendvalid = isset($_REQUEST["sendvalidation"]);
        
        // now for some validation
        $sendback = false;
@@ -83,6 +84,12 @@ function gwvp_AddUserPage()
                $message .= "Passwords dont match. ";
        }
        
+       if($pass1 == "" && $pass2 == "" && !$sendvalid) {
+               $starpass = true;
+               $sendback = true;
+               $message .= "Password was blank. ";
+       }
+       
        // otherwise, its all good, proceed with user creation
        if($sendback) {
                $_SESSION["sendback_owner"] = "users";
@@ -433,6 +440,7 @@ function gwvp_UserAdminPageBody()
                echo "<td>Password Confirm</td><td><input type=\"text\" name=\"pass2\">$starpass</td></tr>";
                echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"$presetusername>$starusername</td>";
                echo "<td>Description</td><td><input type=\"text\" name=\"desc\"$presetdesc></td></tr>";
+               echo "<tr><td colspan=\"4\"><input type=\"checkbox\" name=\"sendvalidation\"> Set account locked and send validation email for initial passsword (not implemented)</td></tr>";
                echo "<tr><td><input type=\"submit\" name=\"Create\" value=\"Create\" class=\"buttons\"></td></tr>";
                echo "</table>";
                echo "</form>";
@@ -572,6 +580,8 @@ function gwvp_UserAdminPageBody()
                }
                trim($ugroups);
                
+               if($ugroups == "") $ugroups = "-";
+               
                switch($LOGIN_TYPE) {
                        case "anon":
                                echo "<tr><td>$username</td><td>$ugroups</td><td>$desc</td></tr>";
diff --git a/gwvplib/plugins/captcha_plugin.php b/gwvplib/plugins/captcha_plugin.php
new file mode 100644 (file)
index 0000000..e952271
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+global $CALL_ME_FUNCTIONS;
+
+$CALL_ME_FUNCTIONS["zzcaptchaimage"] = "gwvp_captchaCallMe";
+
+
+function gwvp_haveCaptcha()
+{
+       $thisloc = realpath(dirname(__FILE__));
+       if(file_exists("$thisloc/securimage/securimage_show.php")) {
+               include_once("$thisloc/securimage/securimage.php");
+               return true;
+       }
+       else return false;
+       
+}
+
+function gwvp_captchaImage()
+{
+       if(gwvp_haveCaptcha()) {
+               $thisloc = realpath(dirname(__FILE__));
+               include("$thisloc/securimage/securimage_show.php");             
+       }
+}
+
+function gwvp_captchaCallMe()
+{
+       if(isset($_REQUEST["q"])) {
+               $query = $_REQUEST["q"];
+               $qspl = explode("/", $query);
+               if($qspl[0] == "securimage") {
+                       error_log("calling captchaimage");
+                       return "gwvp_captchaImage";
+               }
+       }
+       
+       return false;
+}
+
+?>
\ No newline at end of file
index 8bb9bcd..8c32dd3 100644 (file)
Binary files a/www/images/star.jpg and b/www/images/star.jpg differ