summaryrefslogtreecommitdiff
path: root/framework/Security/TUserManager.php
diff options
context:
space:
mode:
authorxue <>2005-11-16 21:18:15 +0000
committerxue <>2005-11-16 21:18:15 +0000
commit455faa0a6a6f3c6d3fac751149781e3e3100cc7e (patch)
tree49fc4757561422eb6a2c7f93cb05d93a098590d5 /framework/Security/TUserManager.php
parentfc5531044911c6fb36f1609bcc10338a81f4eeb0 (diff)
added role support to TUserManager
Diffstat (limited to 'framework/Security/TUserManager.php')
-rw-r--r--framework/Security/TUserManager.php41
1 files changed, 32 insertions, 9 deletions
diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php
index ce4d0343..efa17616 100644
--- a/framework/Security/TUserManager.php
+++ b/framework/Security/TUserManager.php
@@ -84,13 +84,19 @@ class TUser extends TComponent implements IUser
{
$this->_roles=array();
foreach(explode(',',$value) as $role)
- $this->_roles[]=trim($value);
+ {
+ if(($role=trim($role))!=='')
+ $this->_roles[]=$role;
+ }
}
}
public function isInRole($role)
{
- return in_array($role,$this->_roles);
+ foreach($this->_roles as $r)
+ if(strcasecmp($role,$r)===0)
+ return true;
+ return false;
}
public function saveToString()
@@ -116,13 +122,22 @@ class TUserManager extends TComponent implements IModule
{
private $_id;
private $_users=array();
+ private $_roles=array();
private $_guestName='Guest';
private $_passwordMode='MD5';
public function init($application,$config)
{
foreach($config->getElementsByTagName('user') as $node)
- $this->_users[$node->getAttribute('name')]=$node->getAttribute('password');
+ $this->_users[strtolower($node->getAttribute('name'))]=$node->getAttribute('password');
+ foreach($config->getElementsByTagName('role') as $node)
+ {
+ foreach(explode(',',$node->getAttribute('users')) as $user)
+ {
+ if(($user=trim($user))!=='')
+ $this->_roles[strtolower($user)][]=$node->getAttribute('name');
+ }
+ }
}
public function getID()
@@ -161,6 +176,7 @@ class TUserManager extends TComponent implements IModule
$password=md5($password);
else if($this->_passwordMode==='SHA1')
$password=sha1($password);
+ $username=strtolower($username);
return (isset($this->_users[$username]) && $this->_users[$username]===$password);
}
@@ -168,6 +184,7 @@ class TUserManager extends TComponent implements IModule
{
$user->setIsGuest(true);
$user->setName($this->getGuestName());
+ $user->setRoles(array());
}
public function getUser($username=null)
@@ -178,14 +195,20 @@ class TUserManager extends TComponent implements IModule
$user->setIsGuest($username===null);
return $user;
}
- else if(isset($this->_users[$username]))
+ else
{
- $user=new TUser($this);
- $user->setName($username);
- return $user;
+ $username=strtolower($username);
+ if(isset($this->_users[$username]))
+ {
+ $user=new TUser($this);
+ $user->setName($username);
+ if(isset($this->_roles[$username]))
+ $user->setRoles($this->_roles[$username]);
+ return $user;
+ }
+ else
+ return null;
}
- else
- return null;
}
}