Commit a68ca043 authored by 郭勇志's avatar 郭勇志

授权判断

parent a28ad944
...@@ -6,7 +6,8 @@ use Yii; ...@@ -6,7 +6,8 @@ use Yii;
use yii\base\ActionFilter; use yii\base\ActionFilter;
use yii\helpers\StringHelper; use yii\helpers\StringHelper;
use app\models\v1\rbacuser\ShopRbacUser; use app\models\v1\rbacuser\ShopRbacUser;
use yii\web\HttpException; use yii\web\ForbiddenHttpException;
use yii\web\UnauthorizedHttpException;
class authorizationFilter extends ActionFilter class authorizationFilter extends ActionFilter
{ {
public $optional; public $optional;
...@@ -16,21 +17,24 @@ class authorizationFilter extends ActionFilter ...@@ -16,21 +17,24 @@ class authorizationFilter extends ActionFilter
if ($this->isOptional($action)) { if ($this->isOptional($action)) {
return true; return true;
} }
$userGuid = Yii::$app->user->identity->GUID; if (isset(Yii::$app->user->identity->GUID)) {
$url = Yii::$app->request->pathInfo; $userGuid = Yii::$app->user->identity->GUID;
$shopRbacUser = ShopRbacUser::find() $url = Yii::$app->request->pathInfo;
->from('shop_rbac_user sru') $shopRbacUser = ShopRbacUser::find()
->select('sru.GUID') ->from('shop_rbac_user sru')
->leftJoin('shop_rbac_role_user srru', 'srru.USER_ID = sru.GUID') ->select('sru.GUID')
->leftJoin('shop_rbac_role_access srra', 'srra.ROLE_ID = srru.ROLE_ID') ->leftJoin('shop_rbac_role_user srru', 'srru.USER_ID = sru.GUID')
->leftJoin('shop_rbac_node srn', 'srn.ID = srra.NODE_ID') ->leftJoin('shop_rbac_role_access srra', 'srra.ROLE_ID = srru.ROLE_ID')
->where(['srn.NAME' => $url]) ->leftJoin('shop_rbac_node srn', 'srn.ID = srra.NODE_ID')
->andWhere(['sru.GUID' => $userGuid]) ->where(['srn.NAME' => $url])
->all(); ->andWhere(['sru.GUID' => $userGuid])
if (!empty($shopRbacUser)) { ->all();
return true; if (!empty($shopRbacUser)) {
return true;
}
throw new ForbiddenHttpException('没有权限访问此接口');
} }
throw new HttpException('403','没有权限访问此接口'); throw new UnauthorizedHttpException();
} }
/** /**
* Checks, whether authentication is optional for the given action. * Checks, whether authentication is optional for the given action.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment