From: paulr Date: Tue, 16 Nov 2010 14:22:46 +0000 (+1100) Subject: cleaned up the example code. X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=commitdiff_plain;h=195c42d5711d000a987ed3a0a376ac09b98867fc cleaned up the example code. added a new example --- diff --git a/doco/TODO.txt b/doco/TODO.txt index a0e158c..d0ff031 100644 --- a/doco/TODO.txt +++ b/doco/TODO.txt @@ -3,6 +3,8 @@ The Almighty TODO list: 1) Error checking, lots of error checking and sanity checking Then i need to setup error codes and stuff. 2) a "hasToken" method for determining if a user has a token or not 3) implement googles key integrity algorithm thing +4) make a better example +5) rename lib.php to something more appropriate Maybe: Move to exceptions diff --git a/example/old/tokenstore.php b/example/old/tokenstore.php index 97b8ae7..d6a1130 100644 --- a/example/old/tokenstore.php +++ b/example/old/tokenstore.php @@ -1,7 +1,7 @@ query($sql); + + // check the result + if(!$result) return false; + + // now just retreieve all the data (there should only be one, but whatever) + $tokendata = false; + foreach($result as $row) { + $tokendata = $row["tokendata"]; + } + + // now we have our data, we just return it. If we got no data + // we'll just return false by default + return $tokendata; + + // and there you have it, simple eh? + } + + + // now we need a function for putting the data back into our user table. + // in this example, we wont check anything, we'll just overwrite it. + function putData($username, $data) { + // get our database connection + $dbObject = GetDatabase(); + + // set the sql for updating the data + // token data is stored as a base64 encoded string, it should + // not need to be escaped in any way prior to storing in a database + // but feel free to call your databases "addslashes" (or whatever) + // function on $data prior to doing the SQL. + $sql = "update users set tokendata='$data' where username='$username'" + + // now execute the sql and return straight away - you should probably + // clean up after yourselves, but im going to assume pdo does this + // for us anyway in this exmaple + if($dbObject->query($sql)) { + return true; + } else { + return false; + } + + // even simpler! + } + + // the get users method isnt actually used within the google authenticator + // class as yet, but it probably will in the future, so feel free to implement it + function getUsers() { + // get our database connection + $dbObject = GetDatabase(); + + // now the sql again + $sql = "select username from users"; + + // run the query + $result = $dbObject->query($sql); + + // iterate over the results - we expect a simple array containing + // a list of usernames + $i = 0; + $users = array(); + foreach($result as $row) { + $users[$i] = $row["username"]; + $i++; + } + + // now return the list + return $users; + } +} + +// and thats it... +?> \ No newline at end of file