public function actionCreate() { $model = new AuthItem(); if (Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post()) && $model->validate()) { $otherPermission = Yii::$app->request->post('otherpermission'); $otherRole = Yii::$app->request->post('otherrole'); $auth = Yii::$app->authManager; $role = $auth->createRole($model->name); $role->description = $model->description; $auth->add($role); if (!empty($otherPermission) && is_array($otherPermission)) { foreach ($otherPermission as $permission) { $child_permission = $auth->getPermission($permission); if (!empty($child_permission)) { $auth->addChild($role, $child_permission); } } } if (!empty($otherRole) && is_array($otherRole)) { foreach ($otherRole as $therole) { $child_role = $auth->getRole($therole); if (!empty($child_role)) { $auth->addChild($role, $child_role); } } } Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data role has been successfully saved')); return $this->redirect(['create']); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data role failed to save')); } } return $this->render('create', ['model' => $model]); }
public function actionCreate() { $model = new AuthItem(); if (Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post()) && $model->validate()) { $parents = Yii::$app->request->post('parent'); $auth = Yii::$app->authManager; $permission = $auth->createPermission($model->name); $permission->description = $model->description; $auth->add($permission); if (!empty($parents) && is_array($parents)) { foreach ($parents as $parent) { $child_permission = $auth->getPermission($parent); if (!empty($child_permission)) { $auth->addChild($permission, $child_permission); } } } Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data permission has been successfully saved')); return $this->redirect(['create']); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data permission failed to save')); } } return $this->render('create', ['model' => $model]); }
/** * Creates a new AuthItem model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { $model = new AuthItem(); if ($model->load(Yii::$app->request->post())) { $item = $this->model2Item($model, new Role()); $this->auth->add($item); $groupName = YiiForum::getPostValue('AuthItem')['group']; $group = new Role(); if ($groupName) { $group->name = $groupName; $this->auth->addChild($group, $item); } else { //判断角色根是否存在 $rootRole = $this->auth->getRole('root_role'); if (!$rootRole) { $model2 = new AuthItem(); $model2->name = 'root_role'; $model2->description = '角色根'; $model2->rule_name = ''; $model2->data = ''; $item2 = $this->model2Item($model2, new Role()); $this->auth->add($item2); } $group->name = 'root_role'; $this->auth->addChild($group, $item); AuthItem::createCachedRolesGroup(); } return $this->redirect(['index']); } else { $locals = []; $locals['groups'] = YiiForum::getAppParam('cachedRolesGroup'); $locals['model'] = $model; return $this->render('create', $locals); } }
/** * Creates a new AuthItem model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new AuthItem(); if ($model->load(Yii::$app->request->post())) { $model->rule_name = !empty($model->rule_name) ? $model->rule_name : NULL; $model->save(); return $this->redirect(['view', 'id' => $model->name]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new AuthItem model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('createAuthItem')) { $model = new AuthItem(); if ($model->load(Yii::$app->request->post())) { $model->created_at = time(); $model->updated_at = time(); $model->save(); return $this->redirect(['view', 'id' => $model->name]); } else { return $this->render('create', ['model' => $model]); } } else { throw new ForbiddenHttpException(); } }
public function actionCreate() { $model = new AuthItem(); if (Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post()) && $model->validate()) { $auth = Yii::$app->authManager; $permission = $auth->createPermission($model->name); $permission->description = $model->description; $auth->add($permission); Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data route has been successfully saved')); return $this->redirect(['create']); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data route failed to save')); } } return $this->render('create', ['model' => $model]); }
/** * 新建角色 * @return {[type]} [description] * @version 1.0 2016-01-22T11:58:03+0800 * @author cnzhangxl@foxmail.com */ public function actionCreate() { $model = new AuthItem(['scenario' => 'create']); if ($model->load(Yii::$app->request->post())) { $auth = Yii::$app->authManager; if (Item::TYPE_PERMISSION == $model->type) { $operator_obj = $auth->createPermission($model->name); $operator_obj->description = $model->description; $auth->add($operator_obj); if (Yii::$app->request->post('parent_auth_item')) { $auth->addChild($auth->getPermission(Yii::$app->request->post('parent_auth_item')), $operator_obj); } } else { if (Item::TYPE_ROLE == $model->type) { $role = $auth->createRole($model->name); $role->description = $model->description; $auth->add($role); } } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new AuthItem model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { $model = new AuthItem(); 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(); if ($categoryName) { $category->name = $categoryName; $this->auth->addChild($category, $item); } else { $rootPermission = $this->auth->getPermission('root_permission'); if (!$rootPermission) { $model2 = new AuthItem(); $model2->name = 'root_permission'; $model2->description = '权限根'; $model2->rule_name = ''; $model2->data = ''; $item2 = $this->model2Item($model2, new Permission()); $this->auth->add($item2); } $category->name = 'root_permission'; $this->auth->addChild($category, $item); AuthItem::createCachedPermissionsGroup(); } return $this->redirect(['index']); } else { $locals = []; $locals['groups'] = YiiForum::getAppParam('cachedPermissionsGroup'); $locals['model'] = $model; //var_dump(Yii::$app->params); //exit; return $this->render('create', $locals); } }
/** * ajax验证角色是否存在 * @return array */ public function actionValidateitemname() { if ($name = $_REQUEST['id']) { $model = AuthItem::findOne($name); } else { $model = new AuthItem(); } if (Yii::$app->request->isAjax) { $model->load(Yii::$app->request->post()); Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } }