Dropped Redis model, rebuilt without it
The model was getting a bit more complicated than I would have liked. Went back to using straight redis commands and moved some of the user model logic into the custommodule.
This commit is contained in:
parent
2c5144f026
commit
c1817a24be
13 changed files with 69 additions and 198 deletions
|
@ -6,7 +6,7 @@ class AnonymousModule extends CustomModule
|
|||
{
|
||||
parent::__construct();
|
||||
|
||||
if (User::isAuthenticated())
|
||||
if ($this->uid)
|
||||
{
|
||||
Browser::goHome();
|
||||
}
|
||||
|
|
|
@ -3,12 +3,24 @@
|
|||
class CustomModule extends Module
|
||||
{
|
||||
protected $redis = false;
|
||||
protected $uid = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->redis = new CustomRedis();
|
||||
|
||||
if (isset($_COOKIE['__auth']))
|
||||
{
|
||||
list($uid, $auth_token) = explode('|', base64_decode($_COOKIE['__auth']));
|
||||
|
||||
if ($this->redis->hget('user:' . $uid, 'auth') === $auth_token)
|
||||
{
|
||||
$this->uid = $uid;
|
||||
$this->return['uid'] = $uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
|
||||
class RedisModel extends Object
|
||||
{
|
||||
protected $redis = false;
|
||||
protected $prefix = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->redis = new CustomRedis();
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
$parts = func_get_args();
|
||||
|
||||
if ($this->prefix)
|
||||
{
|
||||
array_unshift($parts, $this->prefix);
|
||||
}
|
||||
|
||||
return strtolower(implode(':', $parts));
|
||||
}
|
||||
|
||||
public function mappingKey($variable, $value)
|
||||
{
|
||||
return $this->key($variable, $value, 'uid');
|
||||
}
|
||||
|
||||
public function nextUID()
|
||||
{
|
||||
return $this->redis->incr($this->key('uid'));
|
||||
}
|
||||
|
||||
public function setMapping($variable, $value, $uid)
|
||||
{
|
||||
$this->redis->set($this->mappingKey($variable, $value), $uid);
|
||||
}
|
||||
|
||||
public function getMapping($variable, $value)
|
||||
{
|
||||
return $this->redis->get($this->mappingKey($variable, $value));
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
|
||||
if ($name == 'set')
|
||||
{
|
||||
// Grabs our variables
|
||||
$uid = $arguments[0];
|
||||
$variables = $arguments[1];
|
||||
$arguments = array();
|
||||
|
||||
// Assembles our new arguments
|
||||
foreach ($variables as $key => $value)
|
||||
{
|
||||
$arguments[$this->key($uid, $key)] = $value;
|
||||
}
|
||||
|
||||
// Sets us up for MSET or just SET
|
||||
if (count($arguments) > 1)
|
||||
{
|
||||
$name = 'mset';
|
||||
$arguments = array($arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
$arguments = array(key($arguments), current($arguments));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$base = substr($name, 0, 3);
|
||||
|
||||
if (in_array($base, array('set', 'get')))
|
||||
{
|
||||
$key = $this->key($arguments[0], substr($name, 3));
|
||||
$name = $base;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
case 'get':
|
||||
$arguments = array($key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return call_user_func_array(array($this->redis, $name), $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -6,7 +6,7 @@ class UserModule extends CustomModule
|
|||
{
|
||||
parent::__construct();
|
||||
|
||||
if (!User::isAuthenticated())
|
||||
if (!$this->uid)
|
||||
{
|
||||
Browser::redirect('/login');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue