diff --git a/modules/leaderboard/create.php b/modules/leaderboard/create.php index f0ad3cc..5a38a4a 100644 --- a/modules/leaderboard/create.php +++ b/modules/leaderboard/create.php @@ -12,7 +12,7 @@ class leaderboard_create extends leaderboard_new public function __default() { - // Checks the current UID value + // Grabs the next UID $uid_key = 'leaderboard:uid'; if ($this->redis->get($uid_key) === false) @@ -26,10 +26,15 @@ class leaderboard_create extends leaderboard_new } $timestamp = time(); + $record = array( + 'name' => $_POST['name'], + 'uid' => $this->uid, + 'created_at' => $timestamp, + ); // Creates the rest of the data for the leaderboard $this->redis->multi() - ->hmset('leaderboard:' . $uid, array('name' => $_POST['name'], 'uid' => $this->uid)) + ->hmset('leaderboard:' . $uid, $record) ->zadd('user:' . $this->uid . ':leaderboards:updated', $timestamp, $uid) ->zadd('leaderboards:updated', $timestamp, $uid) ->exec(); diff --git a/modules/leaderboards.php b/modules/leaderboards.php index 587e83a..0206b28 100644 --- a/modules/leaderboards.php +++ b/modules/leaderboards.php @@ -6,7 +6,7 @@ class leaderboards extends UserModule { // Grabs the user's leaderboards $leaderboards = $this->redis->zrevrange('user:' . $this->uid . ':leaderboards:updated', 0, -1, 'WITHSCORES'); - $names = array(); + $data = array(); if ($leaderboards) { @@ -17,15 +17,15 @@ class leaderboards extends UserModule foreach ($leaderboards as $uid => $updated_at) { $leaderboard_uids[] = $uid; - $this->redis->hget('leaderboard:' . $uid, 'name'); + $this->redis->hmget('leaderboard:' . $uid, array('name', 'created_at')); } - $names = array_combine($leaderboard_uids, $this->redis->exec()); + $data = array_combine($leaderboard_uids, $this->redis->exec()); } return array( 'leaderboards' => $leaderboards, - 'names' => $names, + 'data' => $data, ); } } diff --git a/modules/user/create.php b/modules/user/create.php index 4d168f6..243ed39 100644 --- a/modules/user/create.php +++ b/modules/user/create.php @@ -45,7 +45,17 @@ class user_create extends AnonymousModule } // Grabs the next UID - $uid = $this->redis->incr('user:uid'); + $uid_key = 'user:uid'; + + if ($this->redis->get($uid_key) === false) + { + $uid = 1000000; + $this->redis->set($uid_key, $uid); + } + else + { + $uid = $this->redis->incr($uid_key); + } // Generates the auth token $auth_token = sha1(microtime()); @@ -67,11 +77,12 @@ class user_create extends AnonymousModule // Writes the user data $this->redis->hmset('user:' . $uid, array( - 'username' => $_POST['username'], - 'email' => $_POST['email'], - 'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'), - 'auth' => $auth_token, - 'api' => $api_key, + 'username' => $_POST['username'], + 'email' => $_POST['email'], + 'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'), + 'auth' => $auth_token, + 'api' => $api_key, + 'created_at' => time(), )); $mapping_fields[] = 'user:api:' . $api_key; diff --git a/templates/api.phtml b/templates/api.phtml index 88e572d..7ba8a12 100644 --- a/templates/api.phtml +++ b/templates/api.phtml @@ -25,9 +25,9 @@ if ($this->module['api_key'])

All API calls start with {version} where {version} corresponds to the version of the API you would like to use.

-

The current version of the API is v1.0

+

The current version of the API is v1

- +

Authentication

diff --git a/templates/leaderboards.phtml b/templates/leaderboards.phtml index 100383c..d121373 100644 --- a/templates/leaderboards.phtml +++ b/templates/leaderboards.phtml @@ -11,25 +11,39 @@ module['leaderboards']) { - echo ''; - echo ''; - - foreach ($this->module['leaderboards'] as $uid => $updated_at) - { - ?> - - - - - - -
UIDNameLast Activity
module['names'][$uid]; ?> - Delete - Edit -
'; + ?> + + + + + + + + + + module['leaderboards'] as $uid => $updated_at) + { + $data = $this->module['data'][$uid]; + ?> + + + + + + + + + +
UIDNameCreatedLast Activity
+
+ Delete + Edit +
+
+