initial setup pages
[gwvp.git] / gwvplib / gwvpauth.php
1 <?php
2
3 $CALL_ME_FUNCTIONS["00aaa"] = "gwvp_AuthCallMe";
4
5 function gwvp_AuthCallMe()
6 {
7         session_start();
8         
9         if(isset($_REQUEST["q"])) {
10                 $query = $_REQUEST["q"];
11                 if($query == "login") return "gwvp_AuthHandleLogin";
12                 if($query == "register") return "gwvp_RegistrationCall";
13                 else return false;
14         }
15         
16         return false;
17 }
18
19 function gwvp_RegistrationCall()
20 {
21         if(gwvp_IsRegistrationEnabled()) {
22                 gwvp_goMainPage("gwvp_RegistrationPageBody");
23         } else {
24                 gwvp_goMainPage("gwvp_RegistrationDisabledBody");
25         }
26 }
27
28 function gwvp_AuthHandleLogin()
29 {
30         global $BASE_URL;
31         $user = "";
32         $pass = "";
33         if(isset($_REQUEST["username"])) $user = $_REQUEST["username"];
34         if(isset($_REQUEST["password"])) $pass = $_REQUEST["password"];
35         
36         // auth the user
37         if($user == "user" && $pass == "pass") {
38                 $_SESSION["isloggedin"] = true;
39                 $_SESSION["username"] = "user";
40         } else {
41                 gwvp_SendMessage("error", "Login Failed");
42         }
43         
44         header("Location: $BASE_URL");
45 }
46
47 function gwvp_RegistrationPageBody()
48 {
49         ?>
50         <form method="post">
51         <table>
52         <tr><td>Name</td><td><input name="name" type="text"></td><td>Your Full Name</td></tr>
53         <tr><td>Email</td><td><input name="email" type="text"></td><td>Your Email Address</td></tr>
54         <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>
55         <tr><td><input type="submit" name="register" value="Register"></td></tr>
56         </table>
57         </form>
58         <?php
59 }
60
61 function gwvp_IsLoggedIn()
62 {
63         if(isset($_SESSION["isloggedin"])) {
64                 if($_SESSION["isloggedin"]) {
65                         return $_SESSION["username"];
66                 } else return false;
67         } else return false;
68 }
69
70 function gwvp_SingleLineLoginForm()
71 {
72         global $BASE_URL;
73         
74         echo "<form method=\"post\" action=\"$BASE_URL/login\">Username <input type=\"text\" name=\"username\" class=\"login\">";
75         echo " Passowrd <input type=\"text\" name=\"password\" class=\"login\"><input type=\"submit\" name=\"login\" value=\"Login\" class=\"loginbutton\">";
76         if(gwvp_IsRegistrationEnabled()) echo "<a href=\"$BASE_URL/register\">Register</a></form>";
77         else echo "</form>";
78 }
79
80
81 function gwvp_IsRegistrationEnabled()
82 {
83         return true;
84 }
85
86 // TODO translate info here
87 function gwvp_GetFullName($login)
88 {
89         return $login;
90 }
91 ?>