예제 #1
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (!Yii::$app->user->isGuest) {
         throw new HttpException(401, 'Your are already logged in! - Logout first!');
     }
     return parent::beforeAction($action);
 }
 public function beforeAction($action)
 {
     if (!Yii::$app->user->getIdentity()->isModuleEnabled('calendar')) {
         throw new HttpException('500', 'Calendar module is not enabled for your user!');
     }
     return parent::beforeAction($action);
 }
 public function beforeAction($action)
 {
     if (function_exists('opcache_reset')) {
         opcache_reset();
     }
     /**
      * Load language
      */
     $languages = $this->module->getLanguages();
     if (count($languages) == 0) {
         throw new HttpException(404, 'No language available!');
     }
     $this->language = Yii::$app->request->get('language', array_values($languages)[0]);
     if (!in_array($this->language, $languages)) {
         throw new HttpException(404, 'Language not found!');
     }
     /**
      * Load given Module Class
      */
     $this->moduleId = Yii::$app->request->get('moduleId', 'core');
     if (!in_array($this->moduleId, array_keys($this->module->getModuleIds()))) {
         throw new HttpException(404, 'Module not found!');
     }
     /**
      * Load given File 
      */
     $files = $this->module->getFiles($this->moduleId, $this->language);
     if (count($files) == 0) {
         throw new HttpException(400, 'Files not found!');
     }
     $this->file = Yii::$app->request->get('file', '');
     if (!in_array($this->file, $this->module->getFiles($this->moduleId, $this->language))) {
         $this->file = array_values($files)[0];
     }
     /**
      * Get Messages
      */
     $this->messages = array();
     $this->messageFileName = $this->module->getTranslationFile($this->moduleId, $this->language, $this->file);
     if (file_exists($this->messageFileName)) {
         $this->messages = $this->module->getTranslationMessages($this->messageFileName);
     }
     return parent::beforeAction($action);
 }
예제 #4
0
 /**
  * Before each config controller action check if
  *  - Database Connection works
  *  - Database Migrated Up
  *  - Not already configured (e.g. update)
  *
  * @param boolean
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         // Flush Caches
         Yii::$app->cache->flush();
         // Database Connection seems not to work
         if (!$this->module->checkDBConnection()) {
             $this->redirect(Url::to(['/installer/setup']));
             return false;
         }
         // When not at index action, verify that database is not already configured
         if ($action->id != 'finished') {
             if ($this->module->isConfigured()) {
                 $this->redirect(Url::to(['finished']));
                 return false;
             }
         }
         return true;
     }
     return false;
 }
예제 #5
0
 /**
  * Automatically loads the by content or content addon given by parameter.
  * className & id
  *
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     $modelClass = Yii::$app->request->get('contentModel');
     $pk = (int) Yii::$app->request->get('contentId');
     // Fixme
     if ($modelClass == '') {
         $modelClass = Yii::$app->request->post('contentModel');
         $pk = (int) Yii::$app->request->post('contentId');
     }
     if ($modelClass == "" || $pk == "") {
         throw new HttpException(500, 'Model & ID parameter required!');
     }
     \humhub\libs\Helpers::CheckClassType($modelClass, array(ContentAddonActiveRecord::className(), ContentActiveRecord::className()));
     $target = $modelClass::findOne(['id' => $pk]);
     if ($target === null) {
         throw new HttpException(500, 'Could not find underlying content or content addon record!');
     }
     if ($target instanceof ContentAddonActiveRecord) {
         $this->parentContentAddon = $target;
         $this->parentContent = $target->getSource();
     } else {
         $this->parentContent = $target;
     }
     if (!$this->parentContent->content->canRead()) {
         throw new HttpException(403, 'Access denied!');
     }
     $this->contentModel = get_class($target);
     $this->contentId = $target->getPrimaryKey();
     return parent::beforeAction($action);
 }
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         // Directly redirect guests to login page - if guest access isn't enabled
         if (Yii::$app->user->isGuest && Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess') != 1) {
             Yii::$app->user->loginRequired();
             return false;
         }
         return true;
     }
     return false;
 }
예제 #7
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     // Remove authClient from session - if already exists
     Yii::$app->session->remove('authClient');
     return parent::beforeAction($action);
 }