public function beforeAction($action) { if ($action->id == 'index' && Yii::$app->request->referrer !== null) { Yii::$app->session->set('returnUrl', Yii::$app->request->referrer); } return parent::beforeAction($action); }
public function beforeAction($action) { if ($action->id === 'result' || $action->id === 'success' || $action->id === 'fail') { $this->enableCsrfValidation = false; } return parent::beforeAction($action); }
/** * @inheritdoc */ public function beforeAction($action) { if (Yii::$app->user->isGuest) { return false; } return parent::beforeAction($action); }
public function beforeAction($action) { if (in_array($action->id, $this->needAuthActions)) { $this->layout = 'controlpanel'; } return parent::beforeAction($action); }
public function beforeAction($action) { if (!parent::beforeAction($action)) { return false; } //Allow access when srbac is in debug mode if (!\Yii::$app->getModule('rbac')->rbacCheck) { return true; } // 先判断是否为module $mod = $this->module !== null && $this->module->id != \Yii::$app->id ? $this->module->id . $this->delimeter : ""; $access = $mod . ucfirst($this->id) . $this->action->id; // 先检查配置文件中的始终允许(modules配置中的$allowed),再检查数据库设置中的始终允许 $alwaysAllowed = \Yii::$app->getModule('rbac')->allowed; if ($alwaysAllowed) { if (in_array(strtolower($access), $alwaysAllowed)) { return true; } } // 检查数据库中存储的始终允许 $allowed = $this->allowedAccess(); if (array_key_exists($access, $allowed)) { return true; } // Check for rbac access in RBAC Modules Components/SDbAuthManager if (\Yii::$app->user->getIsGuest() || !\Yii::$app->authManager->checkAccess($access)) { return $this->onUnauthorizedAccess(); } else { return true; } }
public function beforeAction($action) { $config = []; switch ($action->id) { case 'quiz': $config = ['steps' => ['question'], 'timeout' => 30, 'forwardOnly' => true, 'events' => [WizardBehavior::EVENT_WIZARD_STEP => [$this, $action->id . 'WizardStep'], WizardBehavior::EVENT_AFTER_WIZARD => [$this, $action->id . 'AfterWizard'], WizardBehavior::EVENT_STEP_EXPIRED => [$this, $action->id . 'StepExpired']]]; break; case 'registration': $config = ['steps' => ['profile', 'address', 'phoneNumber', 'user'], 'events' => [WizardBehavior::EVENT_WIZARD_STEP => [$this, $action->id . 'WizardStep'], WizardBehavior::EVENT_AFTER_WIZARD => [$this, $action->id . 'AfterWizard'], WizardBehavior::EVENT_INVALID_STEP => [$this, 'invalidStep']]]; break; case 'survey': $config = ['steps' => ['havePet', ['hasPet' => ['type', ['cat' => ['cat'], 'dog' => ['dog'], 'pet' => ['pet']]], 'noPet' => ['getPet', ['willGet' => ['get']]]]], 'autoAdvance' => false, 'defaultBranch' => false, 'events' => [WizardBehavior::EVENT_WIZARD_STEP => [$this, $action->id . 'WizardStep'], WizardBehavior::EVENT_AFTER_WIZARD => [$this, $action->id . 'AfterWizard'], WizardBehavior::EVENT_INVALID_STEP => [$this, 'invalidStep']]]; break; case 'resume': $config = ['steps' => []]; // force attachment of WizardBehavior // force attachment of WizardBehavior default: break; } if (!empty($config)) { $config['class'] = WizardBehavior::className(); $this->attachBehavior('wizard', $config); } return parent::beforeAction($action); }
public function beforeAction($action) { if (parent::beforeAction($action)) { return true; } return false; }
public function beforeAction($action) { if (parent::beforeAction($action)) { $request = Yii::$app->getRequest(); $response = Yii::$app->getResponse(); //is this a set-language post request? if ($request->isPost && null !== ($language = $request->get('set-language'))) { $languages = Yii::$app->params['languages']; if (isset($languages[$language])) { $response->cookies->add(new \yii\web\Cookie(['name' => 'language', 'value' => $language])); } $response->refresh(); return false; } //else, read language cookie $cookies = $request->cookies; if (!empty($cookies['language'])) { Yii::$app->language = $cookies['language']->value; } //page size request? $pageSize = filter_input(INPUT_GET, 'page_size', FILTER_VALIDATE_INT); if ($pageSize && in_array($pageSize, Yii::$app->params['admin.page.sizes'])) { Yii::$app->session->set('admin.page.size', $pageSize); unset($_GET['page_size']); } return true; } return false; }
public function beforeAction($action) { if (Yii::$app->request->enableSslRoutes) { /** * This piece of code here is to allow partial SSL for the minute while we cannot fully use SSL all over the site */ $found = false; foreach (Yii::$app->request->sslRoutes as $route) { if ($route == Yii::$app->controller->id . '/' . Yii::$app->controller->action->id) { $found = true; if (!Yii::$app->request->getIsSecureConnection() && !isset(error_get_last()['type'])) { $sslUrl = Yii::$app->getUrlManager()->createAbsoluteUrl(Yii::$app->request->absoluteUrl, 'https'); return Yii::$app->controller->redirect($sslUrl)->send(); } } } if (Yii::$app->request->getIsSecureConnection() && !$found && Yii::$app->controller->id . '/' . Yii::$app->controller->action->id !== 'site/error') { $httpUrl = Yii::$app->getUrlManager()->createAbsoluteUrl(Yii::$app->request->absoluteUrl, 'http'); return Yii::$app->controller->redirect($httpUrl)->send(); } } if (Yii::$app->user->enableTier2 && !Yii::$app->user->getIsGuest() && Yii::$app->session->get('tier2Timeout') > time()) { Yii::$app->session->set('tier2Timeout', Yii::$app->user->tier2Timeout); } return parent::beforeAction($action); }
public function beforeAction($action) { if (Yii::$app->user->isGuest && $this->route != 'site/login') { $this->redirect(['/site/login']); } if ($this->module->id == 'main' && Yii::$app->session['api_url'] == NULL) { $this->redirect(['/site/index']); } $this->authRoute(); $menus = Yii::$app->params['menu']; if ($this->app_code != null) { $tools = (require Yii::getAlias('@backend/config/app/' . $this->app_code . '.php')); if (!$tools) { throw new InvalidConfigException('Loss your app config'); } array_splice($menus, 1, 0, $tools); } $activeTag = ''; $menus = $this->normalizeMenu($menus, $activeTag); if (isset($menus[$activeTag]['items'])) { $this->leftMenu = $menus[$activeTag]['items']; } else { $this->leftMenu = []; } foreach ($menus as $key => $items) { unset($menus[$key]['items']); } $this->topMenu = $menus; return parent::beforeAction($action); }
/** * beforeAction function. * * @access public * @param mixed $action * @return void */ public function beforeAction($action) { $result = parent::beforeAction($action); $options = ['tinymce' => \Yii::$app->urlManager->createUrl('/filemanager/files/tinymce'), 'properties' => \Yii::$app->urlManager->createUrl('/filemanager/files/properties')]; $this->getView()->registerJs("filemanager.init(" . json_encode($options) . ");", \yii\web\View::POS_END, 'my-options'); return $result; }
public function beforeAction($action) { if ($this->action->id == 'pay-out') { $this->enableCsrfValidation = false; } return parent::beforeAction($action); }
public function beforeAction($action) { if ($action->id == 'error') { $this->layout = 'main.php'; } return parent::beforeAction($action); }
public function beforeAction($action) { if (\Yii::$app->user->isGuest) { return $this->goHome(); } return parent::beforeAction($action); }
/** * @inheritDoc */ public function beforeAction($action) { if ($action->id == 'crop-avatar') { $this->enableCsrfValidation = false; } return parent::beforeAction($action); }
public function beforeAction($action) { if (in_array($action->id, ['incoming'])) { $this->enableCsrfValidation = false; } return parent::beforeAction($action); }
public function beforeAction($action) { if (!$this->module->checkAccess(Yii::$app)) { throw new ForbiddenHttpException(); } return parent::beforeAction($action); }
public function beforeAction($action) { if ($action->id === 'success' || $action->id === 'fail' || $action->id === 'pending' || $action->id === 'info73234234') { $this->enableCsrfValidation = false; } return parent::beforeAction($action); }
public function beforeAction($action) { Yii::$app->controller->enableCsrfValidation = false; if (parent::beforeAction($action)) { return true; } }
public function beforeAction($action) { if (parent::beforeAction($action)) { //读取站点配置 $config = Config::find(['id' => 1])->asArray()->one(); if ($config) { $this->view->params['siteconfig'] = $config; } else { die('site config is error'); } if (!Yii::$app->session->isActive) { Yii::$app->session->open(); } if (Yii::$app->session->hasFlash("key")) { $xxxaaa = Yii::$app->session->getFlash("key"); if ($xxxaaa) { echo "<script>alert('" . $xxxaaa . "');</script>"; } unset($xxxaaa); } return true; } else { return false; } }
/** * @inheritdoc */ public function beforeAction($action) { if ($this->id != 'oauth2') { $server = Yii::$app->getModule('oauth2')->getServer(); $request = Yii::$app->getModule('oauth2')->getRequest(); $server->verifyResourceRequest($request); $response = $server->getResponse(); $isValid = true; if ($response !== null) { $isValid = $response->isInformational() || $response->isSuccessful() || $response->isRedirection(); } if (!$isValid) { $status = $response->getStatusCode(); $message = Yii::t('oauth2server', $response->getParameter('error_description')); if ($message === null) { $message = Yii::t('yii', 'An internal server error occurred.'); } throw new HttpException($status, $message); } if (in_array(Yii::$app->request->method, array('POST', 'PUT', 'DELETE'))) { Yii::$app->request->setRawBody($request->content); } } return parent::beforeAction($action); }
public function beforeAction($action) { // $this->enableCsrfValidation = !(($action->id == "auth") or ($action->id == "in") or ($action->id =="set-user-data") // or ($action->id == "test-rsa") or ($action->id == "test-en") ); $this->enableCsrfValidation = false; return parent::beforeAction($action); }
/** * @inheritdoc */ public function beforeAction($action) { if ($action->id == 'error') { Yii::$app->grom->applyErrorLayout(); } return parent::beforeAction($action); }
/** * @inheritdoc * * @param \yii\base\Action $action * @return bool|\yii\web\Response * @throws \yii\web\BadRequestHttpException */ public function beforeAction($action) { if (Yii::$app->user->isGuest) { return $this->redirect(['/passport/account/login']); } return parent::beforeAction($action); }
public function beforeAction($action) { if ($action->id == 'my-method') { $this->enableCsrfValidation = false; } return parent::beforeAction($action); }
public function beforeAction($action) { if (parent::beforeAction($action)) { //menu $id = isset($_GET['id']) ? $_GET['id'] : 0; $rootId = $id > 0 ? BlogCatalog::getRootCatalogId($id, BlogCatalog::find()->all()) : 0; $allCatalog = BlogCatalog::findAll(['parent_id' => 0]); foreach ($allCatalog as $catalog) { $item = ['label' => $catalog->title, 'active' => $catalog->id == $rootId]; if ($catalog->redirect_url) { // redirect to other site $item['url'] = $catalog->redirect_url; } else { $item['url'] = Yii::$app->getUrlManager()->createUrl(['/blog/default/catalog/', 'id' => $catalog->id, 'surname' => $catalog->surname]); } if (!empty($item)) { array_push($this->mainMenu, $item); } } Yii::$app->params['mainMenu'] = $this->mainMenu; return true; // or false if needed } else { return false; } }
public function beforeAction($action) { /** * @var $user \common\models\User */ $beforeAction = parent::beforeAction($action); if (!\Yii::$app->request->isAjax) { $log = new LogMain(); $log->ip = \Yii::$app->request->getUserIP(); $log->referrer = \Yii::$app->request->getReferrer(); $log->method = \Yii::$app->request->getMethod(); $log->action = $action->id; $log->controller = $this->id; $log->data = \Yii::$app->request->getBodyParams() ? json_encode(\Yii::$app->request->getBodyParams()) : null; $log->url = \Yii::$app->getRequest()->getAbsoluteUrl(); $log->user_id = \Yii::$app->user->getId(); $log->agent = \Yii::$app->request->getUserAgent(); $log->robot = \Yii::$app->request->getIsRobot(); $log->insert(false); } if (!\Yii::$app->user->isGuest) { $user = \Yii::$app->user->identity; //если пользователь не обновлялся более 60 секунд, то обновляем данные в объекте, но не делаем запрос в БД, // вдруг где то в контроллере уже делает апдейт, что бы не делать лишний запрос к БД if ($user->updated_at < time() - Time::SEC_TO_MINUTE) { $user->online = true; $user->created_at = time(); } } return $beforeAction; }
/** * @inheritdoc */ public function beforeAction($action) { if (parent::beforeAction($action)) { $excludeActions = $this->excludeActions(); if (in_array($action->id, $excludeActions)) { return true; } if ($this->user->isGuest) { throw new UnauthorizedHttpException(); } if ($this->id == 'site') { return true; } /* @var $identity \app\models\admin */ $identity = $this->user->identity; if ($identity->admin_role_id == 1) { return true; } $acls = $identity->adminRole->acls; $define = static::acls(); if (isset($acls[$this->id])) { foreach ($acls[$this->id] as $rule => $true) { if (isset($define[$rule]) && isset($define[$rule]['actions']) && in_array($action->id, $define[$rule]['actions'])) { return true; } } } throw new ForbiddenHttpException(); } return true; }
public function beforeAction($action) { if (parent::beforeAction($action)) { //menu $id = Yii::$app->request->get('id'); $rootId = $id ? CmsCatalog::getRootCatalogId($id, CmsCatalog::find()->asArray()->all()) : 0; $allCatalog = CmsCatalog::find()->where(['status' => Status::STATUS_ACTIVE, 'is_nav' => CmsCatalog::IS_NAV_YES])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all(); foreach ($allCatalog as $catalog) { $item = ['label' => $catalog->title, 'active' => $catalog->id == $rootId]; if ($catalog->redirect_url) { // redirect to other site $item['url'] = $catalog->redirect_url; } else { $item['url'] = Yii::$app->getUrlManager()->createUrl(['/cms/default/' . $catalog->page_type . '/', 'id' => $catalog->id, 'surname' => $catalog->surname]); } if (!empty($item)) { array_push($this->mainMenu, $item); } } Yii::$app->params['mainMenu'] = $this->mainMenu; return true; // or false if needed } else { return false; } }
public function beforeAction($action) { if (defined('YII_DEBUG') && YII_DEBUG) { Yii::$app->assetManager->forceCopy = true; } return parent::beforeAction($action); }