/** * 当同步接口访问的时候,添加用户验证逻辑 * @param type $action * @return boolean */ public function beforeAction($action) { parent::beforeAction($action); //如果是授权请求,返回true;否则false $this->hasAuthorize(); return true; }
public function beforeAction($action) { parent::beforeAction($action); if (!in_array($action->id, ['login', 'error', 'captcha', 'upfile'])) { $url = Url::toRoute('/site/login'); if (empty($this->user)) { $this->helpGo($url); } $pass_flag = $this->hasSecurity(); if (!$pass_flag && $this->user->is_super !== 1) { $this->helpRefresh($url, '请确认是否有权限访问'); } } return true; }