forked from crisu83/yii-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthWebUser.php
executable file
·64 lines (58 loc) · 1.73 KB
/
AuthWebUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* AuthWebUser class file.
* @author Christoffer Niska <[email protected]>
* @copyright Copyright © Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package auth.components
*/
/**
* Web user that allows for passing access checks when enlisted as an administrator.
*
* @property boolean $isAdmin whether the user is an administrator.
*/
class AuthWebUser extends CWebUser
{
/**
* @var string[] a list of names for the users that should be treated as administrators.
*/
public $admins = array('admin');
/**
* Initializes the component.
*/
public function init()
{
parent::init();
$this->setIsAdmin(in_array($this->name, $this->admins));
}
/**
* Returns whether the logged in user is an administrator.
* @return boolean the result.
*/
public function getIsAdmin()
{
return $this->getState('__isAdmin', false);
}
/**
* Sets the logged in user as an administrator.
* @param boolean $value whether the user is an administrator.
*/
public function setIsAdmin($value)
{
$this->setState('__isAdmin', $value);
}
/**
* Performs access check for this user.
* @param string $operation the name of the operation that need access check.
* @param array $params name-value pairs that would be passed to business rules associated
* with the tasks and roles assigned to the user.
* @param boolean $allowCaching whether to allow caching the result of access check.
* @return boolean whether the operations can be performed by this user.
*/
public function checkAccess($operation, $params = array(), $allowCaching = true)
{
if ($this->getIsAdmin())
return true;
return parent::checkAccess($operation, $params, $allowCaching);
}
}