11ab6b758381100df72e00a079df8347f69d652d
[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                                 $sql = "insert into users values (NULL, '$username', '$fullname', '0')";
14                                 $db = getDatabase();
15                                 $db->query($sql);
16                                 closeDatabase($db);
17                                 
18                                 header("Location: index.php?success=created");
19                                 break;
20                         case "provision":
21                                 $username = $_REQUEST["user"];
22                                 $tokentype = $_REQUEST["tokentype"];
23                                 $myga->setUser($username, $tokentype);
24                                 
25                                 header("Location: index.php?success=Provisioned");
26                                 break;
27                         case "auth":
28                                 $username = $_REQUEST["user"];
29                                 $tokencode = $_REQUEST["tokencode"];
30                                 
31                                 if($myga->authenticateUser($username, $tokencode)) {
32                                         header("Location: index.php?success=Passed");
33                                 } else {
34                                         header("Location: index.php?failure=wrongcode");
35                                 }
36                                 break;
37                 }
38         }
39 }
40 ?>