1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\components; |
4
|
|
|
|
5
|
|
|
class User extends \yii\web\User |
6
|
|
|
{ |
7
|
147 |
|
public function init() |
8
|
|
|
{ |
9
|
147 |
|
parent::init(); |
10
|
|
|
|
11
|
147 |
|
if (!$this->getIsGuest() && !$this->getIdentity()->isActive()) { |
12
|
|
|
$this->logout(); |
13
|
|
|
} |
14
|
147 |
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Checks if the user can perform the operation as specified by the given permission. |
18
|
|
|
* |
19
|
|
|
* Note that you must configure "authManager" application component in order to use this method. |
20
|
|
|
* Otherwise an exception will be thrown. |
21
|
|
|
* |
22
|
|
|
* @param string $permissionName the name of the permission (e.g. "edit post") that needs access check. |
23
|
|
|
* @param array $params name-value pairs that would be passed to the rules associated |
24
|
|
|
* with the roles and permissions assigned to the user. A param with name 'user' is added to |
25
|
|
|
* this array, which holds the value of [[id]]. |
26
|
|
|
* @param boolean $allowCaching whether to allow caching the result of access check. |
27
|
|
|
* When this parameter is true (default), if the access check of an operation was performed |
28
|
|
|
* before, its result will be directly returned when calling this method to check the same |
29
|
|
|
* operation. If this parameter is false, this method will always call |
30
|
|
|
* [[\yii\rbac\ManagerInterface::checkAccess()]] to obtain the up-to-date access result. Note that this |
31
|
|
|
* caching is effective only within the same request and only works when `$params = []`. |
32
|
|
|
* @return boolean whether the user can perform the operation as specified by the given permission. |
33
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
34
|
|
|
*/ |
35
|
66 |
|
public function can($permissionName, $params = [], $allowCaching = true) |
36
|
|
|
{ |
37
|
66 |
|
if (!$this->getIsGuest() && $this->getIdentity()->isSuperUser()) { |
38
|
52 |
|
return true; |
39
|
|
|
} |
40
|
63 |
|
return parent::can($permissionName, $params, $allowCaching); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|