X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=authserver%2Flib%2Flib.php;h=dbdd35f8c9683cfbf6590afae611186903c06152;hp=efc6d95a58fb5556813966d64c87f2e40e909caf;hb=1065be060c1b237c4fcdfdef6e3e2ee663d1ca33;hpb=bd517aaa43fe3437889f4199730bcab1a8519168 diff --git a/authserver/lib/lib.php b/authserver/lib/lib.php index efc6d95..dbdd35f 100644 --- a/authserver/lib/lib.php +++ b/authserver/lib/lib.php @@ -1,32 +1,37 @@ query($sql); } @@ -39,6 +44,7 @@ function closeDatabase($db) { class gaasGA extends GoogleAuthenticator { function getData($username) { + echo "called into getdata\n"; // get our database connection $dbObject = getDatabase(); @@ -50,14 +56,17 @@ class gaasGA extends GoogleAuthenticator { $result = $dbObject->query($sql); // check the result + echo "next1\n"; if(!$result) return false; // now just retreieve all the data (there should only be one, but whatever) + echo "next2\n"; $tokendata = false; foreach($result as $row) { $tokendata = $row["users_tokendata"]; } - + + echo "next3, $username, $tokendata\n"; // now we have our data, we just return it. If we got no data // we'll just return false by default return $tokendata; @@ -66,33 +75,27 @@ class gaasGA extends GoogleAuthenticator { } - // 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 = "delete from users where users_username='$username'"; - $dbObject->query($sql); - - $sql = "insert into users values (NULL, '$username', '$data')"; - + // we need to check if the user exists, and if so put the data, if not create the data + $sql = "select * from users where users_username='$username'"; + $res = $dbObject->query($sql); + if($res->fetchColumn() > 0) { + // do update + $sql = "update users set users_tokendata='$data' where users_username='$username'"; + } else { + // do insert + $sql = "insert into users values (NULL, '$username', '', '', '$data')"; + } - // 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! + } function getUsers() { @@ -119,4 +122,4 @@ class gaasGA extends GoogleAuthenticator { } } -?> \ No newline at end of file +?>