Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: 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);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 3
3
 public function beforeAction($action)
 {
     if ($action->id === 'result' || $action->id === 'success' || $action->id === 'fail') {
         $this->enableCsrfValidation = false;
     }
     return parent::beforeAction($action);
 }
Exemplo n.º 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);
 }
Exemplo n.º 5
3
 /**
  * @param \yii\base\Action $action
  */
 public function beforeAction($action)
 {
     if ($action->controller->id == 'default') {
         \yii\web\Controller::redirect('/staff/admin');
     }
     return true;
 }
Exemplo n.º 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;
 }
Exemplo n.º 9
1
 public function beforeAction($action)
 {
     if (in_array($action->id, $this->needAuthActions)) {
         $this->layout = 'controlpanel';
     }
     return parent::beforeAction($action);
 }
Exemplo n.º 10
1
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->modelTitleForms)) {
         $this->modelTitleForms = PhpMorphy::getNeededForms($this->modelTitle);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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;
         }
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 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();
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 21
0
 public function init()
 {
     parent::init();
     if (Yii::$app->user->identity->id != 1) {
         die('Illegal operation');
     }
 }
Exemplo n.º 22
-1
 public function beforeAction($action)
 {
     if (defined('YII_DEBUG') && YII_DEBUG) {
         Yii::$app->assetManager->forceCopy = true;
     }
     return parent::beforeAction($action);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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();
 }
Exemplo n.º 25
-1
 public function init()
 {
     if ($this->module->customAdminLayout != '') {
         $this->layout = $this->module->customAdminLayout;
     }
     parent::init();
 }
Exemplo n.º 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();
 }
Exemplo n.º 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);
 }
Exemplo n.º 28
-1
 public function getViewPath()
 {
     if ($this->getCart()->module->viewPath) {
         return Yii::getAlias($this->getCart()->module->viewPath . DIRECTORY_SEPARATOR . 'cart');
     }
     return parent::getViewPath();
 }
Exemplo n.º 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++;
         }
     }
 }
Exemplo n.º 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;
     }
 }