Added some created at data and cleaned up some stuff

This commit is contained in:
Josh Sherman 2013-12-17 20:01:33 -05:00
parent 64a246838b
commit 706ebca0cf
5 changed files with 63 additions and 33 deletions

View file

@ -12,7 +12,7 @@ class leaderboard_create extends leaderboard_new
public function __default() public function __default()
{ {
// Checks the current UID value // Grabs the next UID
$uid_key = 'leaderboard:uid'; $uid_key = 'leaderboard:uid';
if ($this->redis->get($uid_key) === false) if ($this->redis->get($uid_key) === false)
@ -26,10 +26,15 @@ class leaderboard_create extends leaderboard_new
} }
$timestamp = time(); $timestamp = time();
$record = array(
'name' => $_POST['name'],
'uid' => $this->uid,
'created_at' => $timestamp,
);
// Creates the rest of the data for the leaderboard // Creates the rest of the data for the leaderboard
$this->redis->multi() $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('user:' . $this->uid . ':leaderboards:updated', $timestamp, $uid)
->zadd('leaderboards:updated', $timestamp, $uid) ->zadd('leaderboards:updated', $timestamp, $uid)
->exec(); ->exec();

View file

@ -6,7 +6,7 @@ class leaderboards extends UserModule
{ {
// Grabs the user's leaderboards // Grabs the user's leaderboards
$leaderboards = $this->redis->zrevrange('user:' . $this->uid . ':leaderboards:updated', 0, -1, 'WITHSCORES'); $leaderboards = $this->redis->zrevrange('user:' . $this->uid . ':leaderboards:updated', 0, -1, 'WITHSCORES');
$names = array(); $data = array();
if ($leaderboards) if ($leaderboards)
{ {
@ -17,15 +17,15 @@ class leaderboards extends UserModule
foreach ($leaderboards as $uid => $updated_at) foreach ($leaderboards as $uid => $updated_at)
{ {
$leaderboard_uids[] = $uid; $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( return array(
'leaderboards' => $leaderboards, 'leaderboards' => $leaderboards,
'names' => $names, 'data' => $data,
); );
} }
} }

View file

@ -45,7 +45,17 @@ class user_create extends AnonymousModule
} }
// Grabs the next UID // 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 // Generates the auth token
$auth_token = sha1(microtime()); $auth_token = sha1(microtime());
@ -67,11 +77,12 @@ class user_create extends AnonymousModule
// Writes the user data // Writes the user data
$this->redis->hmset('user:' . $uid, array( $this->redis->hmset('user:' . $uid, array(
'username' => $_POST['username'], 'username' => $_POST['username'],
'email' => $_POST['email'], 'email' => $_POST['email'],
'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'), 'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'),
'auth' => $auth_token, 'auth' => $auth_token,
'api' => $api_key, 'api' => $api_key,
'created_at' => time(),
)); ));
$mapping_fields[] = 'user:api:' . $api_key; $mapping_fields[] = 'user:api:' . $api_key;

View file

@ -25,9 +25,9 @@ if ($this->module['api_key'])
<p class="lead">All <?php echo $site; ?> API calls start with <span class="label label-primary"><?php echo $url; ?>{version}</span> where <span class="label label-primary">{version}</span> corresponds to the version of the API you would like to use.</p> <p class="lead">All <?php echo $site; ?> API calls start with <span class="label label-primary"><?php echo $url; ?>{version}</span> where <span class="label label-primary">{version}</span> corresponds to the version of the API you would like to use.</p>
<p class="lead">The current version of the <?php echo $site; ?> API is <span class="label label-primary">v1.0</span></p> <p class="lead">The current version of the <?php echo $site; ?> API is <span class="label label-primary">v1</span></p>
<?php $url .= 'v1.0/'; ?> <?php $url .= 'v1/'; ?>
<h2>Authentication</h2> <h2>Authentication</h2>

View file

@ -11,25 +11,39 @@
<?php <?php
if ($this->module['leaderboards']) if ($this->module['leaderboards'])
{ {
echo '<table class="table table-striped table-responsive">'; ?>
echo '<thead><tr><th>UID</th><th>Name</th><th>Last Activity</th><th></th></tr></thead><tbody>'; <table class="table table-striped table-responsive">
<thead><tr>
foreach ($this->module['leaderboards'] as $uid => $updated_at) <th>UID</th>
{ <th>Name</th>
?> <th>Created</th>
<tr class="lead"> <th>Last Activity</th>
<td><?php echo $uid; ?></td> <th></th>
<td><a href="/leaderboard/<?php echo $uid; ?>"><?php echo $this->module['names'][$uid]; ?></a></td> </tr></thead>
<td><?php echo Time::ago($updated_at); ?></td> <tbody>
<td class="text-right"> <?php
<a class="btn btn-danger" href="/leaderboard/delete/<?php echo $uid; ?>">Delete</a> foreach ($this->module['leaderboards'] as $uid => $updated_at)
<a class="btn btn-primary" href="/leaderboard/edit/<?php echo $uid; ?>">Edit</a> {
</td> $data = $this->module['data'][$uid];
</tr> ?>
<?php <tr class="lead">
} <td><?php echo $uid; ?></td>
<td><a href="/leaderboard/<?php echo $uid; ?>"><?php echo $data['name']; ?></a></td>
echo '</tbody></table>'; <td><?php echo Time::ago($data['created_at']); ?></td>
<td><?php echo Time::ago($updated_at); ?></td>
<td class="text-right">
<div class="btn-group">
<a class="btn btn-danger" href="/leaderboard/delete/<?php echo $uid; ?>">Delete</a>
<a class="btn btn-primary" href="/leaderboard/edit/<?php echo $uid; ?>">Edit</a>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
} }
else else
{ {