Create a new leaderboard

This commit is contained in:
Josh Sherman 2013-12-17 13:05:13 -05:00
parent c1817a24be
commit beea5e57c1
7 changed files with 104 additions and 5 deletions

View file

@ -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.');

View file

@ -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)
{