|
|
@@ -14,6 +14,7 @@ class Controller extends CController
|
|
|
public array $authIds = [];
|
|
|
public array $companyIds = [];
|
|
|
public array $schoolIds = [];
|
|
|
+ private int $_userId = 0;
|
|
|
|
|
|
/**
|
|
|
* 检查请求方是否合法
|
|
|
@@ -66,13 +67,17 @@ class Controller extends CController
|
|
|
{
|
|
|
$this->checkRequest();
|
|
|
|
|
|
+ $token = $_SERVER['HTTP_AUTHORIZATION']?? '';
|
|
|
+ $data = RedisInstance::getInstance()->get('user_token:'.$token);
|
|
|
+ $this->_userId = $data['id']?? 0;
|
|
|
+
|
|
|
Yii::app()->language = 'zh_cn';
|
|
|
$controller = Yii::app()->controller->id;
|
|
|
$action = $this->getAction()->getId();
|
|
|
$path = strtolower($controller . '/'. $action);
|
|
|
if( !in_array($controller, ['site'])
|
|
|
&&!in_array($path, LewaimaiAdminPingtaiAuth::$noLoginRouters)
|
|
|
- && Yii::app()->user->isGuest
|
|
|
+ && !$this->_userId
|
|
|
){
|
|
|
Helper::error('请先登入', 401);
|
|
|
}
|
|
|
@@ -81,7 +86,7 @@ class Controller extends CController
|
|
|
$this->_formatAuth();
|
|
|
|
|
|
if (!LewaimaiAdminPingtaiAuth::adminAuth($controller, $action)
|
|
|
- && (!Yii::app()->user->isGuest && Yii::app()->user->_id != 1)
|
|
|
+ && (!$this->_userId && $this->_userId != 1)
|
|
|
) {
|
|
|
Helper::error('您没有相应的权限');
|
|
|
}
|
|
|
@@ -91,10 +96,10 @@ class Controller extends CController
|
|
|
|
|
|
private function _formatAuth(): void
|
|
|
{
|
|
|
- $key = 'user_auth_' . Yii::app()->user->_id;
|
|
|
+ $key = 'user_auth_' . $this->_userId;
|
|
|
$data = RedisInstance::getInstance()->get($key);
|
|
|
if (!$data) {
|
|
|
- $model = Useradmin::model()->findByPk(Yii::app()->user->_id);
|
|
|
+ $model = Useradmin::model()->findByPk($this->_userId);
|
|
|
$authIds = DB::getScalerWithCriteria(
|
|
|
'role',
|
|
|
DbCriteria::simpleCompare(['id' => $model->role_id])->setSelect('auth_ids')
|
|
|
@@ -114,17 +119,23 @@ class Controller extends CController
|
|
|
$this->companyIds = $data['companyIds'];
|
|
|
$this->schoolIds = $data['schoolIds'];
|
|
|
}
|
|
|
+ LewaimaiAdminPingtaiAuth::$authIds = $this->authIds;
|
|
|
}
|
|
|
|
|
|
public function clearAuth($id = 0)
|
|
|
{
|
|
|
- $id = $id ? $id : Yii::app()->user->_id;
|
|
|
+ $id = $id ? : $this->_userId;
|
|
|
RedisInstance::getInstance()->delete('user_auth_' . $id);
|
|
|
}
|
|
|
|
|
|
+ private function getUserId()
|
|
|
+ {
|
|
|
+ return $this->_userId;
|
|
|
+ }
|
|
|
+
|
|
|
public function getSchoolFilter($filed = 'school_id'):?array
|
|
|
{
|
|
|
- if (Yii::app()->user->_id == 1 || in_array(-1, $this->companyIds)) {
|
|
|
+ if ($this->_userId == 1 || in_array(-1, $this->companyIds)) {
|
|
|
return null;
|
|
|
}
|
|
|
return $this->schoolIds;
|
|
|
@@ -132,7 +143,7 @@ class Controller extends CController
|
|
|
|
|
|
public function checkSchoolId(int $id):bool
|
|
|
{
|
|
|
- if (Yii::app()->user->_id == 1 || in_array(-1, $this->schoolIds)) {
|
|
|
+ if ($this->_userId == 1 || in_array(-1, $this->schoolIds)) {
|
|
|
return true;
|
|
|
}
|
|
|
return in_array($id, $this->schoolIds);
|
|
|
@@ -140,7 +151,7 @@ class Controller extends CController
|
|
|
|
|
|
public function getCompanyFilter():?array
|
|
|
{
|
|
|
- if (Yii::app()->user->_id == 1 || in_array(-1, $this->companyIds)) {
|
|
|
+ if ($this->_userId == 1 || in_array(-1, $this->companyIds)) {
|
|
|
return null;
|
|
|
}
|
|
|
return $this->companyIds;
|
|
|
@@ -148,7 +159,7 @@ class Controller extends CController
|
|
|
|
|
|
public function checkCompanyId(int $id):bool
|
|
|
{
|
|
|
- if (Yii::app()->user->_id == 1 || in_array(-1, $this->companyIds)) {
|
|
|
+ if ($this->_userId == 1 || in_array(-1, $this->companyIds)) {
|
|
|
return true;
|
|
|
}
|
|
|
return in_array($id, $this->companyIds);
|