Esempio n. 1
0
 /**
  * Initial RBAC action
  * @param integer $id Superadmin ID
  */
 public function actionInit($id = null)
 {
     $auth = new PhpManager();
     $auth->init();
     $auth->removeAll();
     //удаляем старые данные
     // Rules
     $groupRule = new GroupRule();
     $auth->add($groupRule);
     // Roles
     $user = $auth->createRole('user');
     $user->description = 'User';
     $user->ruleName = $groupRule->name;
     $auth->add($user);
     $moderator = $auth->createRole('moderator');
     $moderator->description = 'Moderator';
     $moderator->ruleName = $groupRule->name;
     $auth->add($moderator);
     $auth->addChild($moderator, $user);
     $admin = $auth->createRole('admin');
     $admin->description = 'Admin';
     $admin->ruleName = $groupRule->name;
     $auth->add($admin);
     $auth->addChild($admin, $moderator);
     // $auth->assign($admin, 1);
 }
Esempio n. 2
0
 /**
  *
  */
 public function saveItem()
 {
     try {
         $item = $this->type == self::TYPE_ROLE ? $this->_authMan->createRole($this->name) : $this->_authMan->createPermission($this->name);
         $item->name = $this->name;
         $item->type = $this->type;
         $item->description = $this->description;
         $item->createdAt = time();
         $item->updatedAt = time();
         $this->_authMan->add($item);
         return true;
     } catch (\yii\db\Exception $e) {
         if ($e->getCode() == 23000) {
             $this->addError('name', RbacModule::t('simplerbac', 'Item also exists'));
         } else {
             $this->addError('name', 'Error ' . $e->getName() . ' #' . $e->getCode());
         }
         return false;
     }
 }