mirror of
https://github.com/twisterarmy/twister.git
synced 2025-03-12 21:31:26 +00:00
This commit is contained in:
parent
099b5de451
commit
9598fb9bfc
@ -43,6 +43,7 @@ class Container implements ArrayAccess
|
||||
{
|
||||
if (static::$instance)
|
||||
throw new \Exception('Cannot create another Container instance!');
|
||||
|
||||
static::$instance = $this;
|
||||
|
||||
$this->bindings = $c;
|
||||
|
@ -316,11 +316,14 @@ class Request
|
||||
//
|
||||
private function _get_args_from_params(array $params)
|
||||
{
|
||||
/*
|
||||
$byType = [ 'twister\container' => &$this->container,
|
||||
'twister\db' => &$this->db,
|
||||
'twister\user' => &$this->container->user,
|
||||
// 'twister\user' => &$this->container->user,
|
||||
'twister\request' => &$this
|
||||
];
|
||||
*/
|
||||
$byType = $this->requestRouteParams;
|
||||
$args = [];
|
||||
foreach ($params as $param)
|
||||
{
|
||||
@ -616,7 +619,7 @@ class Request
|
||||
|
||||
if (is_array($location))
|
||||
{
|
||||
throw new \Exception('Request section not implemented/RE-written yet!');
|
||||
throw new \Exception('Request section not implemented or re-written yet!');
|
||||
|
||||
if (isset($location['scheme']) && ! isset($location['host']))
|
||||
$location['host'] = _::request('host');
|
||||
|
131
src/User.php
131
src/User.php
@ -1,131 +0,0 @@
|
||||
<?php // AKA player || visitor (bot/agent/human) || manager
|
||||
|
||||
namespace Twister;
|
||||
|
||||
class User
|
||||
{
|
||||
private $container = null;
|
||||
public $id = 0;
|
||||
private $_properties = null;
|
||||
private $db = null;
|
||||
private $_permissions = null;
|
||||
|
||||
public function __construct(Container &$c, array $properties = null)
|
||||
{
|
||||
$this->properties =& $properties;
|
||||
}
|
||||
|
||||
|
||||
function __construct(Container &$c, $id = 0)
|
||||
{
|
||||
$this->container = $c;
|
||||
$this->db = $c->db;
|
||||
|
||||
$this->id = $id;
|
||||
|
||||
if ($id)
|
||||
{
|
||||
$this->load_permissions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get member by id/index
|
||||
*
|
||||
* @param string|int $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
switch ($key)
|
||||
{
|
||||
case 'managers': return $this->_properties[$key] = new Managers::factory();
|
||||
|
||||
}
|
||||
return $this->_properties[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set member by id/index
|
||||
*
|
||||
* @param string|int $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$this->_properties[$key] = $value;
|
||||
}
|
||||
|
||||
public function worlds($key, $value)
|
||||
{
|
||||
if ( ! isset($this->_properties['worlds']))
|
||||
{
|
||||
$sql = 'SELECT * FROM user_worlds WHERE user_id = ' . $this->id;
|
||||
$this->db->get_array($sql);
|
||||
}
|
||||
$this->_properties[$key] = $value;
|
||||
}
|
||||
public function getWorlds($key, $value)
|
||||
{
|
||||
$this->_properties[$key] = $value;
|
||||
}
|
||||
|
||||
public function isManager($id)
|
||||
{
|
||||
return $this->getManagers()
|
||||
}
|
||||
public function getManagers()
|
||||
{
|
||||
if ( ! isset($this->_properties['managers']))
|
||||
{
|
||||
$sql = 'SELECT * FROM user_managers WHERE user_id = ' . $this->id;
|
||||
$this->_properties['managers'] = $this->db->get_array($sql);
|
||||
}
|
||||
return $this->_properties['managers'];
|
||||
}
|
||||
|
||||
function __isset($key)
|
||||
{
|
||||
return isset($this->_properties[$key]);
|
||||
}
|
||||
function __unset($key)
|
||||
{
|
||||
unset($this->_properties[$key]);
|
||||
}
|
||||
|
||||
private function load_permissions()
|
||||
{
|
||||
$this->_permissions = $this->db->get_array( 'SELECT SQL_CACHE ' . // cached because these tables are less frequenty updated!
|
||||
'g.alias as g_alias,' .
|
||||
'p.alias as p_alias,' .
|
||||
'acl.object_id' .
|
||||
' FROM acl' .
|
||||
' JOIN acl_permissions p ON p.id = acl.permission_id' .
|
||||
' JOIN acl_groups g ON g.id = p.group_id' .
|
||||
' WHERE acl.user_id = ' . $this->id .
|
||||
' AND acl.disabled = 0',
|
||||
['g_alias', 'p_alias', 'object_id'], ['object_id']);
|
||||
}
|
||||
function permission($group_alias, $permission_alias, $query_data = null, $object = 0)
|
||||
{
|
||||
if (!is_array($object))
|
||||
{
|
||||
if (isset($this->_permissions[$group_alias][$permission_alias][$object])) return true;
|
||||
}
|
||||
else // used when we want to specify default zero OR a value ... eg. array(0, 13);
|
||||
foreach ($object as $obj) if (isset($this->_permissions[$group_alias][$permission_alias][$obj])) return true;
|
||||
if (isset($this->_permissions['administrators']['super'])) return true; // super-admin bypass!
|
||||
if (isset($query_data))
|
||||
{
|
||||
if (is_string($query_data)) $query_data = ['next' => $query_data];
|
||||
$query_data['warning'] = 'Protected Area! Login with relevant permissions required!'; // <== TODO: Translate this!!! Or send a constant!
|
||||
$this->container->request->redirect('/login?' . http_build_query($query_data));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function permissions($group_alias, $permission_alias)
|
||||
{
|
||||
return isset($this->_permissions[$group_alias][$permission_alias]) ? array_keys($this->_permissions[$group_alias][$permission_alias]) : array();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user