/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByUsername($this->username); } return $this->_user; }
/** * Finds user by [[username, email]] * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findOne(['username' => $this->username, 'email' => $this->email, 'active' => true]); } return $this->_user; }
/** * Задание пароля суперпользователя */ public function actionPassword() { do { $pass = $this->prompt(Yii::t('main/app', 'Input root password:'******'main/app', 'Confirm root password:'), ["required" => true]); $user = User::findOne(["username" => "root"]); $user->password = $pass; $user->confirm_password = $confPass; $res = $user->save(); if (!$res) { foreach ($user->getErrors() as $errorArr) { foreach ($errorArr as $error) { $this->stdout($error . "\n", Console::FG_RED); } } } } while (!$res); return 0; }
/** * @return User возвращает автора модели */ public function getAuthor() { return $this->hasOne(User::className(), ['id' => 'author_id']); }
/** * Связывание ролей с пользователями */ public function assign() { $auth = Yii::$app->authManager; $iterator = User::find()->each(); foreach ($iterator as $model) { $r = $model->role; if ($r) { $auth->revokeAll($model->id); $auth->assign($auth->getRole($r), $model->id); } } }
/** * Тест просмотра пользователя */ public function testViewUser() { $model = User::findOne(["username" => "root"]); $route = $this->viewRoute; $this->getRequest([$route, "id" => $model->id]); $res = Yii::$app->runAction($route, ["id" => $model->id]); $this->specify('action result is text', function () use($res) { $this->assertTrue(strlen($res) > 0); }); }
public function setUp() { parent::setUp(); Yii::$app->user->login(User::findByUsername('root')); }
<?php use app\modules\main\models; return ['controllerMap' => ['migrate' => ['migrationLookup' => ['@webapp/modules/main/migrations']]], 'modules' => ['main' => ['class' => app\modules\main\Main::className(), 'controllerNamespace' => 'app\\modules\\main\\controllers', 'components' => ['tagsConverter' => \common\components\TagsConverter::className(), 'sphinxUrlService' => \app\modules\main\components\SphinxUrlService::className(), 'sitemap' => ["class" => \app\modules\main\sitemap\Sitemap::className(), "definition" => [['class' => 'app\\modules\\main\\models\\Pages', 'urlCreate' => function ($model) { return Yii::$app->urlManager->createUrl(['/main/pages/index', 'model' => $model]); }]]], 'config' => ['class' => \app\modules\main\components\Config::className()], 'treeFinder' => ['class' => \common\components\TreeFinder::className()], 'blocksProvider' => ['class' => \app\modules\main\components\BlocksProvider::className()]], 'modules' => ['admin' => ['class' => app\modules\main\modules\admin\Admin::className(), 'controllerNamespace' => 'app\\modules\\main\\modules\\admin\\controllers', 'menuItems' => function () { return [['label' => Yii::t('main/app', 'Main module'), 'icon' => 'glyphicon glyphicon-home', 'items' => [['label' => Yii::t('main/app', 'Pages'), 'url' => ['/admin/main/pages'], "permission" => ["listModels", ["model" => Yii::createObject(models\Pages::className())]]], ['label' => Yii::t('main/app', 'Menu'), 'url' => ['/admin/main/menu'], "permission" => ["listModels", ["model" => Yii::createObject(models\Menu::className())]]], ['label' => Yii::t('main/app', 'Users'), 'url' => ['/admin/main/user'], "permission" => ["listModels", ["model" => Yii::createObject(models\User::className())]]], ['label' => Yii::t('main/app', 'FileManager'), 'url' => ['/admin/main/file-manager'], "permission" => ["fileManager"]], ['label' => Yii::t('main/app', 'Templates'), 'url' => ['/admin/main/template'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Includes'), 'url' => ['/admin/main/includes'], "permission" => ["listModels", ["model" => Yii::createObject(models\Includes::className())]]], ['label' => Yii::t('main/app', 'Include Groups'), 'url' => ['/admin/main/include-group'], "permission" => ["listModels", ["model" => Yii::createObject(models\IncludeGroup::className())]]], ['label' => Yii::t('main/app', 'Comments'), 'url' => ['/admin/main/comments'], "permission" => ["listModels", ["model" => Yii::createObject(models\Comments::className())]]], ['label' => Yii::t('main/app', 'Reviews'), 'url' => ['/admin/main/review'], "permission" => ["listModels", ["model" => Yii::createObject(models\Review::className())]]], ['label' => Yii::t('main/app', 'Tools'), 'url' => ['/admin/main/tools'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Permission'), 'url' => ['/admin/main/permission'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Config'), 'url' => ['/admin/main/config'], "permission" => ["rootAccess"]]]]]; }]]]], 'components' => ['i18n' => ['translations' => ['main/*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@webapp/modules/main/messages', 'fileMap' => ['main/app' => 'app.php']]]], 'urlManager' => ['rules' => ['user/<action:[A-z0-9_-]+>' => 'main/user/<action>', 'user' => 'main/user/profile', ['class' => '\\app\\modules\\main\\components\\PageUrlRule']]]]];
/** * Действия * @return array */ public function actions() { $class = User::className(); return ['index' => ['class' => crud\Admin::className(), 'modelClass' => $class], 'create' => ['class' => crud\Create::className(), 'modelClass' => $class], 'update' => ['class' => crud\Update::className(), 'modelClass' => $class], 'view' => ['class' => crud\View::className(), 'modelClass' => $class], 'delete' => ['class' => crud\Delete::className(), 'modelClass' => $class], 'groupdelete' => ['class' => crud\GroupDelete::className(), 'modelClass' => $class], 'editable' => ['class' => crud\XEditable::className(), 'modelClass' => $class]]; }
/** * @return \yii\db\ActiveQuery */ public function getCreatedUser() { return $this->hasOne(User::className(), ['id' => 'created_user']); }
/** * @inheritdoc */ protected function config() { return ["model" => ["definition" => ["class" => \common\db\fields\TextField::className(), "title" => Yii::t('main/app', 'Model class'), "isRequired" => true, "editInGrid" => true], "params" => [$this->owner, "model"]], "role" => ["definition" => ["class" => \common\db\fields\ListField::className(), "title" => Yii::t('main/app', 'Role'), "isRequired" => true, "data" => function () { return \app\modules\main\models\User::getRolesNames(); }, "editInGrid" => true], "params" => [$this->owner, "role"]], "create" => ["definition" => ["class" => \common\db\fields\CheckBoxField::className(), "title" => Yii::t('main/app', 'Create'), "editInGrid" => true], "params" => [$this->owner, "create"]], "read" => ["definition" => ["class" => \common\db\fields\CheckBoxField::className(), "title" => Yii::t('main/app', 'Read'), "editInGrid" => true], "params" => [$this->owner, "read"]], "update" => ["definition" => ["class" => \common\db\fields\CheckBoxField::className(), "title" => Yii::t('main/app', 'Update'), "editInGrid" => true], "params" => [$this->owner, "update"]], "delete" => ["definition" => ["class" => \common\db\fields\CheckBoxField::className(), "title" => Yii::t('main/app', 'Delete'), "editInGrid" => true], "params" => [$this->owner, "delete"]], "constraint" => ["definition" => ["class" => \common\db\fields\TextField::className(), "title" => Yii::t('main/app', 'Constraint class'), "editInGrid" => true], "params" => [$this->owner, "constraint"]], "forbidden_attrs" => ["definition" => ["class" => \common\db\fields\TextAreaField::className(), "title" => Yii::t('main/app', 'Forbidden attributes'), "editInGrid" => true], "params" => [$this->owner, "forbidden_attrs"]]]; }
/** * Возвращает список ролей доступных для управления * @return array */ public function getPermittedRoles() { return array_keys(User::getRolesNames()); }
<?php return ['modules' => ['import' => ['class' => 'app\\modules\\import\\Import', 'components' => ['csvImporter' => ['class' => \app\modules\import\components\CsvImporter::className(), 'allowedModels' => [\app\modules\main\models\User::className()]]], 'controllerNamespace' => 'app\\modules\\import\\controllers', 'modules' => ['admin' => ['class' => 'app\\modules\\import\\modules\\admin\\Admin', 'controllerNamespace' => 'app\\modules\\import\\modules\\admin\\controllers', 'menuItems' => function () { return [['label' => Yii::t('import/app', 'Import module'), 'icon' => 'glyphicon glyphicon-import', 'items' => [['label' => Yii::t('import/app', 'Csv import'), 'url' => ['/admin/import/csv-import'], "permission" => ["rootAccess"]]]]]; }]]]], 'components' => ['i18n' => ['translations' => ['import/*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@webapp/modules/import/messages', 'fileMap' => ['import/app' => 'app.php']]]], 'urlManager' => ['rules' => []]]];