From 8610dc0313949920f1d4487a9b7104f2ddbc5d97 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Thu, 22 Nov 2012 14:09:43 -0400 Subject: [PATCH] added handlers for creating and validating tokens --- includes/islandora_authtokens.inc | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 includes/islandora_authtokens.inc diff --git a/includes/islandora_authtokens.inc b/includes/islandora_authtokens.inc new file mode 100644 index 00000000..b938b9d8 --- /dev/null +++ b/includes/islandora_authtokens.inc @@ -0,0 +1,52 @@ +uid . $pid . $dsid . $time); + + $id = db_insert("islandora_authtokens") + ->fields(array( + 'token' => $token, + 'uid' => $user->uid, + 'pid' => $pid, + 'dsid' => $dsid, + 'time' => $time, + )) + ->execute(); + return $token; +} + +function islandora_validate_object_token($pid, $dsid, $token) { + global $user; + // check for database token + $time = time(); + $result = db_select("islandora_authtokens", "id") + ->fields("id") + ->condition('token', $token, '=') + ->condition('uid', $user->uid, '=') + ->condition('pid', $pid, '=') + ->condition('dsid', $dsid, '=') + ->condition('time', $time, '<=') + ->condition('time', $time-TOKEN_TIMEOUT, '>') + ->execute() + ->rowCount(); + + //** this is for one-time use tokens **// + // remove the authtoken (if it exists) so it can't be used again + db_delete("islandora_authtokens") + ->condition('token', $token, '=') + ->condition('uid', $user->uid, '=') + ->condition('pid', $pid, '=') + ->condition('dsid', $dsid, '=') + ->execute(); + +// print_r($result); + return $result > 0; +}