Exemplo n.º 1
0
 /** @inheritdoc */
 protected function validateValue($value)
 {
     if (!is_array($value)) {
         return [\Yii::t('rbac', 'Invalid value'), []];
     }
     foreach ($value as $val) {
         if ($this->manager->getItem($val) == null) {
             return [\Yii::t('rbac', 'There is neither role nor permission with name "{0}"', [$val]), []];
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Updated items children.
  */
 protected function updateChildren()
 {
     $children = $this->manager->getChildren($this->item->name);
     $childrenNames = array_keys($children);
     if (is_array($this->children)) {
         // remove children that
         foreach (array_diff($childrenNames, $this->children) as $item) {
             $this->manager->removeChild($this->item, $children[$item]);
         }
         // add new children
         foreach (array_diff($this->children, $childrenNames) as $item) {
             $this->manager->addChild($this->item, $this->manager->getItem($item));
         }
     } else {
         $this->manager->removeChildren($this->item);
     }
 }
Exemplo n.º 3
0
 /** @inheritdoc */
 public function bootstrap($app)
 {
     /** @var Module $module */
     /** @var \yii\db\ActiveRecord $modelName */
     if ($app->hasModule('user') && ($module = $app->getModule('user')) instanceof Module) {
         Yii::$container->setSingleton(UserFinder::className(), ['userQuery' => \jarrus90\User\models\User::find(), 'profileQuery' => \jarrus90\User\models\Profile::find(), 'tokenQuery' => \jarrus90\User\models\Token::find(), 'accountQuery' => \jarrus90\User\models\Account::find()]);
         if (!isset($app->get('i18n')->translations['rbac'])) {
             $app->get('i18n')->translations['rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => __DIR__ . '/messages', 'sourceLanguage' => 'en-US'];
         }
         if (!isset($app->get('i18n')->translations['user'])) {
             $app->get('i18n')->translations['user'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages', 'sourceLanguage' => 'en-US'];
         }
         if (!$app instanceof ConsoleApplication) {
             $module->controllerNamespace = 'jarrus90\\User\\Controllers';
             if (!Yii::$container->has('yii\\web\\User')) {
                 Yii::$container->set('yii\\web\\User', ['enableAutoLogin' => true, 'loginUrl' => ['/user/security/login'], 'identityClass' => \jarrus90\User\models\User::className()]);
             }
             $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules];
             if ($module->urlPrefix != 'user') {
                 $configUrlRule['routePrefix'] = 'user';
             }
             $configUrlRule['class'] = 'yii\\web\\GroupUrlRule';
             $rule = Yii::createObject($configUrlRule);
             $app->urlManager->addRules([$rule], false);
             if (!$app->has('authClientCollection')) {
                 $app->set('authClientCollection', ['class' => Collection::className()]);
             }
             $app->params['admin']['menu']['user'] = function () use($module) {
                 return $module->getAdminMenu();
             };
             $app->params['admin']['menu']['logout'] = ['label' => Yii::t('user', 'Logout'), 'icon' => '<i class="fa fa-sign-out"></i>', 'url' => '/user/security/logout'];
         } else {
             if (empty($app->controllerMap['migrate'])) {
                 $app->controllerMap['migrate']['class'] = 'yii\\console\\controllers\\MigrateController';
             }
             $app->controllerMap['migrate']['migrationNamespaces'][] = 'jarrus90\\User\\migrations';
         }
         if (!$app->authManager instanceof DbManager) {
             $app->set('authManager', ['class' => DbManager::className(), 'cache' => $app->cache]);
         }
         Yii::$container->set('jarrus90\\User\\Mailer', $module->mailer);
     }
 }
Exemplo n.º 4
0
 /**
  * Returns all available auth items to be attached to user.
  * @return array
  */
 public function getAvailableItems()
 {
     return ArrayHelper::map($this->manager->getItems(), 'name', function ($item) {
         return empty($item->description) ? $item->name : $item->name . ' (' . $item->description . ')';
     });
 }