public function actionIndex() { $authManager = \Yii::$app->getAuthManager(); if (!$authManager instanceof DbManager) { throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.'); } if ((new \yii\db\Query())->select('*')->from($authManager->itemTable)->where('name=:name', [':name' => 'userManager'])->count() > 0) { throw new InvalidConfigException('Illegal attempt to run setup: data already exists.'); } if (null !== User::find()->where(['email' => '*****@*****.**'])->one()) { throw new InvalidConfigException('Illegal attempt to run setup: user admin@admin.com already exists.'); } $admin = new User(); $admin->setPassword('admin'); $admin->email = '*****@*****.**'; $admin->status = User::STATUS_ACTIVE; if (!$admin->save()) { throw new ErrorException('Unable to save default admin user: '******'userManager', 'authItemEditor', 'userAssignRoles', 'authItemEditRule'] as $roleName) { $role = $authManager->createRole($roleName); $authManager->add($role); $authManager->assign($role, $admin->getId()); } }
/** * List all users. */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => User::find()->orderBy('LOWER(email)'), 'pagination' => ['pageSize' => 20]]); return $this->render('@icalab/auth/views/user/index', ['dataProvider' => $dataProvider]); }