diff --git a/modules/leaderboard/create.php b/modules/leaderboard/create.php new file mode 100644 index 0000000..de36b00 --- /dev/null +++ b/modules/leaderboard/create.php @@ -0,0 +1,41 @@ + array( + 'length:>:100' => 'Leaderboard name may not be more than 100 characters.', + ), + ); + + public function __default() + { + // Checks the current UID value + $uid_key = 'leaderboard:uid'; + + if ($this->redis->get($uid_key) === false) + { + $uid = 1000000; + $this->redis->set($uid_key, $uid); + } + else + { + $uid = $this->redis->incr($uid_key); + } + + $timestamp = Time::timestamp(); + + // Creates the rest of the data for the leaderboard + $this->redis->multi() + ->hmset('leaderboard:' . $uid, array('name' => $_POST['name'], 'uid' => $this->uid)) + ->zadd('user:' . $this->uid . ':leaderboards:updated', $timestamp, $uid) + ->zadd('leaderboards:updated', $timestamp, $uid) + ->exec(); + + return array('status' => 'success', 'url' => '/leaderboards'); + } +} + +?> diff --git a/modules/leaderboard/new.php b/modules/leaderboard/new.php new file mode 100644 index 0000000..c50aab7 --- /dev/null +++ b/modules/leaderboard/new.php @@ -0,0 +1,8 @@ + diff --git a/modules/leaderboards.php b/modules/leaderboards.php index bff45cf..a253bb5 100644 --- a/modules/leaderboards.php +++ b/modules/leaderboards.php @@ -5,7 +5,7 @@ class leaderboards extends UserModule public function __default() { // Grabs the user's leaderboards - $leaders = ''; + $leaderboards = array(); return array('leaderboards' => $leaderboards); } diff --git a/modules/user/authenticate.php b/modules/user/authenticate.php index 4e007dc..6c6363a 100644 --- a/modules/user/authenticate.php +++ b/modules/user/authenticate.php @@ -28,7 +28,7 @@ class user_authenticate extends AnonymousModule setcookie('__auth', base64_encode($uid . '|' . $user['auth']), time() + Time::YEAR, '/'); } - return array('status' => 'success', 'url' => '/'); + return array('status' => 'success', 'url' => '/leaderboards'); } return array('error' => 'Invalid email address or password.'); diff --git a/modules/user/create.php b/modules/user/create.php index 2732baf..99ad2f9 100644 --- a/modules/user/create.php +++ b/modules/user/create.php @@ -58,13 +58,30 @@ class user_create extends AnonymousModule 'auth' => $auth_token, )); + // Creates an API key for the user + $api_key = false; + + while (!$api_key) + { + $new_key = sha1(microtime() . mt_rand()); + $redis_key = 'user:api:' . $new_key; + + if ($this->redis->get($redis_key) === false) + { + $api_key = $new_key; + $this->redis->set($redis_key, $api_key); + } + } + + $mapping_fields[] = 'user:api:' . $api_key; + // Sets the UID mappings - $this->redis->mset(array_combine($mapping_fields, array($uid, $uid))); + $this->redis->mset(array_combine($mapping_fields, array($uid, $uid, $uid))); // Sets a cookie with the UID and auth token setcookie('__auth', base64_encode($uid . '|' . $auth_token), time() + Time::YEAR, '/'); - return array('status' => 'success', 'url' => '/'); + return array('status' => 'success', 'url' => '/leaderboards'); } catch (Exception $e) { diff --git a/templates/leaderboard/new.phtml b/templates/leaderboard/new.phtml new file mode 100644 index 0000000..d37f0fb --- /dev/null +++ b/templates/leaderboard/new.phtml @@ -0,0 +1,17 @@ +
diff --git a/templates/leaderboards.phtml b/templates/leaderboards.phtml index f797777..e8179fc 100644 --- a/templates/leaderboards.phtml +++ b/templates/leaderboards.phtml @@ -1,3 +1,19 @@ -