/**
  * Creates a new AuthItem model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $categoryName = YiiForum::getGetValue('category');
     $model = new AuthItem();
     $model->category = $categoryName;
     if ($model->load(Yii::$app->request->post())) {
         $item = $this->model2Item($model, new Permission());
         $this->auth->add($item);
         $categoryName = YiiForum::getPostValue('AuthItem')['category'];
         $category = new Permission();
         $category->name = $categoryName;
         $this->auth->addChild($category, $item);
         AuthItem::createCachedPermissions();
         return $this->redirect(['index', 'category' => $categoryName]);
     } else {
         $locals = [];
         $locals['currentCategory'] = $categoryName;
         $locals['categories'] = $this->getCachedPermissionCategories();
         $locals['model'] = $model;
         return $this->render('create', $locals);
     }
 }
 public function actionRole($id)
 {
     $auth = \Yii::$app->authManager;
     $existItems = $auth->getAssignments($id);
     $model = [];
     if (YiiForum::hasPostValue('submit')) {
         $allRoles = $this->getCachedRoles();
         $selectedRoles = YiiForum::getPostValue('selectedRoles');
         $this->updateAssignments($allRoles, $selectedRoles, $existItems, $id);
         return $this->redirect(['index']);
     } else {
         $allRoles = [];
         $groups = $this->getCachedRoleGroups();
         foreach ($groups as $group) {
             $allRoles[$group['description']] = $this->getCachedRolesByGroup($group['name']);
         }
         $locals = [];
         $locals['model'] = $model;
         $locals['allRoles'] = $allRoles;
         $locals['existRoles'] = $existItems;
         return $this->render('role', $locals);
     }
 }
Exemple #3
0
 public function actionPermission($id)
 {
     $groupName = YiiForum::getGetValue('group');
     $model = $this->findModel($id);
     $existPermissions = $this->getCachedRoles($id)['permissions'];
     if (YiiForum::hasPostValue('submit')) {
         $parent = new Role();
         $parent->name = $id;
         $allPermissions = $this->getCachedPermissions();
         $selectedPermissions = YiiForum::getPostValue('selectedPermissions');
         $this->updatePermissions($allPermissions, $selectedPermissions, $existPermissions, $parent, new Permission());
         AuthItem::createCachedRoles();
         return $this->redirect(['index', 'group' => $groupName]);
     } else {
         $allPermissions = [];
         $categories = $this->getCachedPermissionCategories();
         foreach ($categories as $category) {
             $allPermissions[$category['description']] = $this->getCachedPermissionsByCategory($category['name']);
         }
         $locals = [];
         $locals['currentGroup'] = $groupName;
         $locals['model'] = $model;
         $locals['allPermissions'] = $allPermissions;
         $locals['existPermissions'] = $existPermissions;
         return $this->render('permission', $locals);
     }
 }
 public function actionEditPost($id)
 {
     if (!YiiForum::checkAuth('post_edit')) {
         return $this->noPermission();
     }
     YiiForum::checkIsGuest();
     $boardId = YiiForum::getGetValue('boardid');
     $model = Post::findOne(['id' => $id]);
     $data = YiiForum::getPostValue('Post');
     if ($data == null) {
         $thread = Thread::findOne(['id' => $model['thread_id']]);
         $locals = [];
         $locals['thread'] = $thread;
         $locals['currentBoard'] = $this->getBoard($boardId);
         $locals['model'] = $model;
         return $this->render('edit-post', $locals);
     } else {
         $model->load(Yii::$app->request->post());
         $model->modify_time = TTimeHelper::getCurrentTime();
         $model->save();
         return $this->redirect(['view', 'id' => $model->thread_id]);
     }
 }