Built out logout procedure.

This commit is contained in:
Josh Sherman 2013-12-16 18:24:39 -05:00
parent 29987e8640
commit 74257193f1
4 changed files with 60 additions and 5 deletions

View file

@ -85,6 +85,16 @@ class RedisModel extends Object
switch ($base)
{
case 'set':
if (isset($arguments[1]))
{
$arguments = $arguments[1];
}
else
{
$key = $this->key(substr($name, 3));
var_dump($key, $arguments);
}
$arguments = array($key, $arguments[1]);
break;

View file

@ -4,16 +4,47 @@ class User extends RedisModel
{
protected $prefix = 'user';
public static function isAuthenticated()
public function generateToken()
{
return sha1(mt_rand() . microtime());
}
public function getAuthenticated($fields)
{
if (!is_array($fields))
{
$fields = array($fields);
}
if ($cookie = self::getCookie())
{
if ($fields == array('uid'))
{
return $cookie['uid'];
}
}
return false;
}
public static function getCookie()
{
if (isset($_COOKIE['__auth']))
{
list($uid, $auth_token) = explode('|', base64_decode($_COOKIE['__auth']));
return array_combine(array('uid', 'token'), explode('|', base64_decode($_COOKIE['__auth'])));
}
return false;
}
public static function isAuthenticated()
{
if ($cookie = self::getCookie())
{
$user = new self();
$user_token = $user->getAuth($uid);
$auth_token = $user->getAuth($cookie['uid']);
return $user_token === $auth_token;
return $auth_token === $cookie['token'];
}
}
}

14
modules/logout.php Normal file
View file

@ -0,0 +1,14 @@
<?php
class logout extends UserModule
{
public function __default()
{
$user = new User();
$user->setAuth($user->getAuthenticated('uid'), $user->generateToken());
Browser::goHome();
}
}
?>

View file

@ -38,7 +38,7 @@ class user_create extends AnonymousModule
$uid = $user->nextUID();
// Generates the auth token
$auth_token = sha1(mt_rand() . microtime());
$auth_token = $user->generateToken();
// Writes the user data
$user->set($uid, array(