1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\base\models\web; |
14
|
|
|
|
15
|
|
|
use rhosocial\base\models\models\BaseUserModel; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @version 1.0 |
19
|
|
|
* @author vistart <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class User extends \yii\web\User |
22
|
|
|
{ |
23
|
|
|
private $_access = []; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get the GUID of identity. |
27
|
|
|
* If no user logged-in, null will be given. |
28
|
|
|
* @return null|string |
29
|
|
|
*/ |
30
|
|
|
public function getGuid() |
31
|
|
|
{ |
32
|
|
|
$identity = $this->getIdentity(); |
33
|
|
|
/* @var $identity BaseUserModel */ |
34
|
|
|
return $identity !== null ? $identity->getGUID() : null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $permissionName |
39
|
|
|
* @param array $params |
40
|
|
|
* @param bool $allowCaching |
41
|
|
|
* @return bool|mixed |
42
|
|
|
*/ |
43
|
|
|
public function can($permissionName, $params = [], $allowCaching = true) |
44
|
|
|
{ |
45
|
|
|
if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) { |
46
|
|
|
return $this->_access[$permissionName]; |
47
|
|
|
} |
48
|
|
|
if (($accessChecker = $this->getAccessChecker()) === null) { |
49
|
|
|
return false; |
50
|
|
|
} |
51
|
|
|
$access = $accessChecker->checkAccess($this->getGuid(), $permissionName, $params); |
52
|
|
|
if ($allowCaching && empty($params)) { |
53
|
|
|
$this->_access[$permissionName] = $access; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $access; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|