С версии: 2.0
Автор: Qiang Xue (qiang.xue@gmail.com)
Наследование: extends yii\base\Controller
 /**
  * @param $flag
  * @param $successMessage
  * @param $failedMessage
  *
  * @return \yii\web\Response
  */
 protected function redirectWithMessages($flag, $successMessage, $failedMessage)
 {
     if ($flag) {
         Yii::$app->session->setFlash('success', $successMessage);
         return $this->controller->redirect($this->successUrl);
     } else {
         Yii::$app->session->setFlash('warning', $failedMessage);
         return $this->controller->redirect($this->failedUrl);
     }
 }
Пример #2
3
 /**
  * Returns all available actions of the specified controller.
  * @param Controller $controller the controller instance
  * @return array all available action IDs.
  */
 public function getActions($controller)
 {
     $actions = array_keys($controller->actions());
     $class = new \ReflectionClass($controller);
     foreach ($class->getMethods() as $method) {
         $name = $method->getName();
         if ($name !== 'actions' && $method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0) {
             $actions[] = Inflector::camel2id(substr($name, 6), '-', true);
         }
     }
     sort($actions);
     return array_unique($actions);
 }
Пример #3
3
 public function beforeAction($action)
 {
     if ($action->id === 'result' || $action->id === 'success' || $action->id === 'fail') {
         $this->enableCsrfValidation = false;
     }
     return parent::beforeAction($action);
 }
Пример #4
3
 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);
 }
Пример #5
3
 /**
  * @param \yii\base\Action $action
  */
 public function beforeAction($action)
 {
     if ($action->controller->id == 'default') {
         \yii\web\Controller::redirect('/staff/admin');
     }
     return true;
 }
Пример #6
3
 public function init()
 {
     parent::init();
     $model = new Category();
     $map = ['status' => 1];
     $model->getList($map);
 }
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (Yii::$app->user->isGuest) {
         return false;
     }
     return parent::beforeAction($action);
 }
 /**
  * @inheritdoc
  */
 public function actions()
 {
     $actions = parent::actions();
     $actions['login'] = ['class' => LoginAction::className(), 'modelClass' => $this->modelClass];
     $actions['logout'] = ['class' => LogoutAction::className()];
     return $actions;
 }
Пример #9
1
 public function beforeAction($action)
 {
     if (in_array($action->id, $this->needAuthActions)) {
         $this->layout = 'controlpanel';
     }
     return parent::beforeAction($action);
 }
Пример #10
1
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->modelTitleForms)) {
         $this->modelTitleForms = PhpMorphy::getNeededForms($this->modelTitle);
     }
 }
Пример #11
1
 /**
  * If we are acting in the module context and the layout is empty we only should renderPartial the content.
  *
  * @param string $view   The name of the view file (e.g. index)
  * @param array  $params The params to assign into the value for key is the variable and value the content.
  *
  * @return string
  */
 public function render($view, $params = [])
 {
     if (!empty($this->module->context) && empty($this->layout)) {
         return $this->renderPartial($view, $params);
     }
     return parent::render($view, $params);
 }
Пример #12
1
 /**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', 'Hey! Your new forum account has just been automatically created! Go to {link} to complement it.', ['link' => Html::a(Yii::t('podium/view', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', 'There was an error while creating inherited user account. Podium can not run with the current configuration. Please contact administrator about this problem.'));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
Пример #13
0
 public function init()
 {
     parent::init();
     $n_sr = false;
     $n_ar = false;
     $n_s = false;
     $n_a = false;
     //poka 4to zdes' delaem zada4i controllera no porom nado srochno pereexat'
     if (!Yii::$app->user->isGuest) {
         if (Yii::$app->user->identity->getStageReportNotification()) {
             $n_sr = Yii::$app->user->identity->getStageReportNotification();
         }
         if (Yii::$app->user->identity->getAssignmentReportNotification()) {
             $n_ar = Yii::$app->user->identity->getAssignmentReportNotification();
         }
         if (Yii::$app->user->identity->getStageNotification()) {
             $n_s = Yii::$app->user->identity->getStageNotification();
         }
         if (Yii::$app->user->identity->getAssignmentNotification()) {
             $n_a = Yii::$app->user->identity->getAssignmentNotification();
         }
     }
     Yii::$app->view->params['n_sr'] = $n_sr;
     Yii::$app->view->params['n_ar'] = $n_ar;
     Yii::$app->view->params['n_s'] = $n_s;
     Yii::$app->view->params['n_a'] = $n_a;
 }
Пример #14
0
 /**
  * @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;
 }
 /**
  * @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 init()
 {
     //check for abonnement permission
     $user = Yii::$app->getModule("user")->model("User");
     if (($user = $user::findOne(Yii::$app->user->userid)) !== null) {
         if ($user->abonnement->active == 0) {
             throw new ForbiddenHttpException('
              <div class="text-center">
              <h3>
              <p class="bg-danger">
              <br>Uw abonnement is (nog) niet actief of inmiddels verlopen!<br><br>
              </p>
              </h3>
              <br><br>
              </div>
              <div class="text-center">
              <a href="http://werkmetspoor.nl/index.php/contact/" class="btn btn-danger" role="button">Neem contact met ons op</a>
              </div>
              ');
         }
     }
     // indien igelogged maar geen contactpersoon
     if (!empty(Yii::$app->user) && !Yii::$app->user->can("contactpersoon")) {
         throw new ForbiddenHttpException('Geen toegang');
     }
     parent::init();
 }
Пример #17
0
 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;
     }
 }
Пример #18
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['accessControl'] = $this->accessControlBehavior();
     $behaviors['accessControl']['rules'] = array_merge([['allow' => true, 'actions' => ['grid-view-settings', 'route-to-url'], 'roles' => ['@']]], $behaviors['accessControl']['rules']);
     return $behaviors;
 }
 /**
  * @inheritdoc
  */
 public function afterAction($action, $result)
 {
     if ($this->_oldMailPath !== null) {
         Yii::$app->getMailer()->setViewPath($this->_oldMailPath);
     }
     return parent::afterAction($action, $result);
 }
Пример #20
0
 public function findLayoutFile($view)
 {
     if ($this->layout === null && $this->ajaxLayout !== false && Yii::$app->getRequest()->getIsAjax()) {
         $this->layout = $this->ajaxLayout;
     }
     return parent::findLayoutFile($view);
 }
Пример #21
0
 public function init()
 {
     parent::init();
     if (Yii::$app->user->identity->id != 1) {
         die('Illegal operation');
     }
 }
Пример #22
-1
 public function beforeAction($action)
 {
     if (defined('YII_DEBUG') && YII_DEBUG) {
         Yii::$app->assetManager->forceCopy = true;
     }
     return parent::beforeAction($action);
 }
Пример #23
-1
 public function afterAction($action, $result)
 {
     if (!Yii::$app->user->isGuest) {
         $actionName = "frontend@{$this->module->id}_{$this->id}_{$action->id}";
     }
     return parent::afterAction($action, $result);
 }
Пример #24
-1
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     /*return [
           'access' => [
               'class' => AccessControl::className(),
               'rules' => [
                   [
                       'actions' => ['login', 'error'],
                       'allow' => true,
                   ],
                   [
                       'actions' => ['logout', 'index'],
                       'allow' => true,
                       'roles' => ['@'],
                   ],
               ],
           ],
           'verbs' => [
               'class' => VerbFilter::className(),
               'actions' => [
                   'logout' => ['post'],
               ],
           ],
       ];*/
     parent::behaviors();
 }
Пример #25
-1
 public function init()
 {
     if ($this->module->customAdminLayout != '') {
         $this->layout = $this->module->customAdminLayout;
     }
     parent::init();
 }
Пример #26
-1
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!empty(Yii::$app->user) && !Yii::$app->user->can("contactpersoon")) {
         throw new ForbiddenHttpException('Je hebt geen toegang');
     }
     parent::init();
 }
Пример #27
-1
 public function afterAction($action, $result)
 {
     if (Yii::$app->request->pathInfo !== "auth/index") {
         Url::remember(Url::toRoute(["/" . Yii::$app->request->pathInfo]), 'safe_url');
     }
     return parent::afterAction($action, $result);
 }
Пример #28
-1
 public function getViewPath()
 {
     if ($this->getCart()->module->viewPath) {
         return Yii::getAlias($this->getCart()->module->viewPath . DIRECTORY_SEPARATOR . 'cart');
     }
     return parent::getViewPath();
 }
Пример #29
-1
 public function init()
 {
     parent::init();
     unset(Yii::$app->view->params['blocks']);
     unset(Yii::$app->view->params['categoryColumn1']);
     unset(Yii::$app->view->params['categoryColumn2']);
     Yii::$app->view->params['blocks'] = BlocksSearch::find()->where(['active' => 1])->orderBy('sortOrder ASC')->all();
     $allCategoryCounts = PostsSearch::find()->published()->count();
     if (Yii::$app->params['showNullCategory']) {
         $categories = CategoriesSearch::find()->active()->orderBy('title ASC')->all();
     } else {
         $categories = CategoriesSearch::find()->active()->innerJoin("{{%sources}}", "[[sources.categories_id]]=[[categories.id]]")->innerJoin("{{%posts}}", "[[posts.sources_id]] = [[sources.id]]")->orderBy('title ASC')->groupBy("[[categories.title]]")->all();
     }
     if (is_array($categories)) {
         $i = 1;
         $halfCountCategories = ceil(count($categories) / 2);
         Yii::$app->view->params['categoryColumn1'][] = ['url' => '/', 'title' => Yii::t('app/categories', 'All Categories ({0})', [$allCategoryCounts])];
         foreach ($categories as $category) {
             $countPostInCategory = $category->countPosts;
             $url = Yii::$app->request->get('category') != $category->slugUrl ? $category->url : NULL;
             $title = $category->title;
             if ($i <= $halfCountCategories) {
                 Yii::$app->view->params['categoryColumn1'][] = ['url' => $url, 'title' => $title . " ({$countPostInCategory})"];
             } else {
                 Yii::$app->view->params['categoryColumn2'][] = ['url' => $url, 'title' => $title . " ({$countPostInCategory})"];
             }
             $i++;
         }
     }
 }
Пример #30
-1
 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;
     }
 }