Skip to content

Commit

Permalink
refactor: 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
myloveGy committed Nov 24, 2019
1 parent 7f722a7 commit eac6916
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function init()
* @return bool|\yii\console\Response|\yii\web\Response
* @throws UnauthorizedHttpException
* @throws \yii\base\InvalidConfigException
* @throws \yii\web\ForbiddenHttpException
*/
public function beforeAction($action)
{
Expand All @@ -148,14 +149,16 @@ public function beforeAction($action)
return parent::beforeAction($action);
}

/* @var $webUser \yii\web\User */
$webUser = Yii::$app->get($this->user);
// 验证用户登录
if (Yii::$app->get($this->user)->isGuest) {
Yii::$app->get($this->user)->loginRequired();
if ($webUser->isGuest) {
$webUser->loginRequired();
return false;
}

// 验证权
if ($this->verifyAuthority && !Yii::$app->get($this->user)->can($action->getUniqueId())) {
if ($this->verifyAuthority && !$webUser->can($action->getUniqueId())) {
// 没有权限AJAX返回
if (Yii::$app->request->isAjax) {
Yii::$app->response->content = Json::encode($this->error(216));
Expand Down

0 comments on commit eac6916

Please sign in to comment.