Added a login page example
[ga4php.git] / example / provisioning / input.php
1 <?php
2
3 // this part of the example is the part that processes user inputs from forms
4 function processInput() {
5         global $myga;
6         
7         if(isset($_REQUEST["action"])) {
8                 switch($_REQUEST["action"]) {
9                         case "createuser":
10                                 // "users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT,"users_fullname" TEXT,"users_tokendata" TEXT
11                                 $username = $_REQUEST["username"];
12                                 $fullname = $_REQUEST["fullname"];
13                                 $password = sha1($_REQUEST["password"]);
14                                 $sql = "insert into users values (NULL, '$username', '$fullname', '$password','0')";
15                                 $db = getDatabase();
16                                 $db->query($sql);
17                                 closeDatabase($db);
18                                 
19                                 header("Location: index.php?success=created");
20                                 break;
21                         case "provision":
22                                 $username = $_REQUEST["user"];
23                                 $tokentype = $_REQUEST["tokentype"];
24                                 $myga->setUser($username, $tokentype);
25                                 
26                                 header("Location: index.php?success=Provisioned");
27                                 break;
28                         case "auth":
29                                 $username = $_REQUEST["user"];
30                                 $tokencode = $_REQUEST["tokencode"];
31                                 
32                                 if($myga->authenticateUser($username, $tokencode)) {
33                                         header("Location: index.php?success=Passed");
34                                 } else {
35                                         header("Location: index.php?failure=wrongcode");
36                                 }
37                                 break;
38                 }
39         }
40 }
41 ?>