added more framework bits,
[gwvp.git] / gwvplib / gwvpauth.php
diff --git a/gwvplib/gwvpauth.php b/gwvplib/gwvpauth.php
new file mode 100644 (file)
index 0000000..27afec8
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+$CALL_ME_FUNCTIONS["00aaa"] = "gwvp_AuthCallMe";
+
+function gwvp_AuthCallMe()
+{
+       session_start();
+       
+       if(isset($_REQUEST["q"])) {
+               $query = $_REQUEST["q"];
+               if($query == "login") return "gwvp_AuthHandleLogin";
+               if($query == "register") return "gwvp_RegistrationCall";
+               else return false;
+       }
+       
+       return false;
+}
+
+function gwvp_RegistrationCall()
+{
+       if(gwvp_IsRegistrationEnabled()) {
+               gwvp_goMainPage("gwvp_RegistrationPageBody");
+       } else {
+               gwvp_goMainPage("gwvp_RegistrationDisabledBody");
+       }
+}
+
+function gwvp_AuthHandleLogin()
+{
+       global $BASE_URL;
+       $user = "";
+       $pass = "";
+       if(isset($_REQUEST["username"])) $user = $_REQUEST["username"];
+       if(isset($_REQUEST["password"])) $pass = $_REQUEST["password"];
+       
+       // auth the user
+       if($user == "user" && $pass == "pass") {
+               $_SESSION["isloggedin"] = true;
+               $_SESSION["username"] = "user";
+       } else {
+               gwvp_SendMessage("error", "Login Failed");
+       }
+       
+       header("Location: $BASE_URL");
+}
+
+function gwvp_RegistrationPageBody()
+{
+       ?>
+       <form method="post">
+       <table>
+       <tr><td>Name</td><td><input name="name" type="text"></td><td>Your Full Name</td></tr>
+       <tr><td>Email</td><td><input name="email" type="text"></td><td>Your Email Address</td></tr>
+       <tr><td>Nick Name</td><td><input name="nickname" 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>
+       </table>
+       </form>
+       <?php
+}
+
+function gwvp_IsLoggedIn()
+{
+       if(isset($_SESSION["isloggedin"])) {
+               if($_SESSION["isloggedin"]) {
+                       return $_SESSION["username"];
+               } else return false;
+       } else return false;
+}
+
+function gwvp_SingleLineLoginForm()
+{
+       global $BASE_URL;
+       
+       echo "<form method=\"post\" action=\"$BASE_URL/login\">Username <input type=\"text\" name=\"username\" class=\"login\">";
+       echo " Passowrd <input type=\"text\" name=\"password\" class=\"login\"><input type=\"submit\" name=\"login\" value=\"Login\" class=\"loginbutton\">";
+       if(gwvp_IsRegistrationEnabled()) echo "<a href=\"$BASE_URL/register\">Register</a></form>";
+       else echo "</form>";
+}
+
+
+function gwvp_IsRegistrationEnabled()
+{
+       return true;
+}
+
+// TODO translate info here
+function gwvp_GetFullName($login)
+{
+       return $login;
+}
+?>
\ No newline at end of file