X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=authserver%2Flib%2Flib.php;h=cf4c39e43dc923c13764a3f8185fe5d5865ec7b0;hp=efc6d95a58fb5556813966d64c87f2e40e909caf;hb=d1eae3d523f459b4cdd5e1bfc776690d0ad96069;hpb=ae879118f79612ed5ded5c52fa695f7074b4c461 diff --git a/authserver/lib/lib.php b/authserver/lib/lib.php index efc6d95..cf4c39e 100644 --- a/authserver/lib/lib.php +++ b/authserver/lib/lib.php @@ -1,32 +1,35 @@ query($sql); } @@ -66,33 +69,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 = $dbOject->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() {