/** * * @param \talview\sesmailer\Message $message * * @return bool */ protected function sendMessageAsync($message) { try { return $this->client->sendRawEmailAsync(['RawMessage' => ['Data' => base64_encode($message->getSwiftMessage())]]); } catch (SesException $e) { Console::output($e->getMessage()); Yii::error($e->getMessage()); } return false; }
public function actionInit() { $auth = Yii::$app->authManager; $user = $auth->createRole(User::ROLE_USER); $auth->add($user); Console::output('Success! RBAC roles has been added.'); }
public function actionInit() { $auth = Yii::$app->authManager; $auth->removeAll(); $user = $auth->createRole(User::ROLE_USER); $user->description = 'User'; $auth->add($user); // own model rule $ownModelRule = new OwnModelRule(); $auth->add($ownModelRule); $manager = $auth->createRole(User::ROLE_MANAGER); $manager->description = 'Manager'; $auth->add($manager); $auth->addChild($manager, $user); $loginToBackend = $auth->createPermission('loginToBackend'); $loginToBackend->description = 'Login to backend'; $auth->add($loginToBackend); $auth->addChild($manager, $loginToBackend); $admin = $auth->createRole(User::ROLE_ADMINISTRATOR); $admin->description = 'Administrator'; $auth->add($admin); $auth->addChild($admin, $manager); $auth->assign($admin, 1); Console::output('Success! RBAC roles has been added.'); }
/** * 初始默认角色数据 */ public function initRbac() { Console::output('初始化RBAC数据 ....'); $auth = Yii::$app->authManager; /* ================= 权限 ================= */ $visitAdmin = $auth->createPermission('visitAdmin'); $visitAdmin->description = '访问后台管理界面权限'; $auth->add($visitAdmin); /* ================= 身份 ================= */ $guest = $auth->createRole('guest'); // 匿名用户 $guest->description = '匿名用户'; $auth->add($guest); $user = $auth->createRole('user'); //普通用户 $user->description = '普通用户'; $auth->add($user, $guest); //普通用户 > 匿名用户 $admin = $auth->createRole('admin'); // 管理员 $admin->description = '管理员'; $auth->add($admin); $auth->addChild($admin, $user); // 管理员 > 普通用户 $auth->addChild($admin, $visitAdmin); // 管理员可以访问后台 $founder = $auth->createRole('founder'); // 创始人 $founder->description = '创始人'; $auth->add($founder); $auth->addChild($founder, $admin); // 创始人 > 管理员 Console::output('初始化RBAC数据完成 ....'); }
public function actionInit() { $auth = Yii::$app->authManager; $auth->removeAll(); $user = $auth->createRole(User::ROLE_USER); $auth->add($user); // own model rule $ownModelRule = new OwnModelRule(); $auth->add($ownModelRule); $manager = $auth->createRole(User::ROLE_MANAGER); $auth->add($manager); $auth->addChild($manager, $user); $loginToBackend = $auth->createPermission('loginToBackend'); $auth->add($loginToBackend); $auth->addChild($manager, $loginToBackend); $publisher = $auth->createRole(User::ROLE_PUBLISHER); $auth->add($publisher); $auth->addChild($publisher, $loginToBackend); $advertiser = $auth->createRole(User::ROLE_ADVERTISER); $auth->add($advertiser); $auth->addChild($advertiser, $loginToBackend); $admin = $auth->createRole(User::ROLE_ADMINISTRATOR); $auth->add($admin); $auth->addChild($admin, $manager); $auth->assign($admin, 1); $auth->assign($manager, 2); $auth->assign($user, 3); $auth->assign($publisher, 4); $auth->assign($advertiser, 5); Console::output('Success! RBAC roles has been added.'); }
public function actionInit() { $auth = Yii::$app->authManager; $auth->removeAll(); $user = $auth->createRole(User::ROLE_USER); $auth->add($user); // own model rule $ownModelRule = new OwnModelRule(); $auth->add($ownModelRule); $submissionRule = new SubmissionRule(); $auth->add($submissionRule); $updateOwnResearch = $auth->createPermission('updateOwnResearch'); $updateOwnResearch->description = 'update research by status'; $updateOwnResearch->ruleName = $submissionRule->name; $auth->add($updateOwnResearch); $auth->addChild($user, $updateOwnResearch); $manager = $auth->createRole(User::ROLE_MANAGER); $auth->add($manager); $auth->addChild($manager, $user); $loginToBackend = $auth->createPermission('loginToBackend'); $auth->add($loginToBackend); $auth->addChild($manager, $loginToBackend); $admin = $auth->createRole(User::ROLE_ADMINISTRATOR); $auth->add($admin); $auth->addChild($admin, $manager); $auth->assign($admin, 1); $auth->assign($manager, 2); $auth->assign($user, 3); Console::output('Success! RBAC roles has been added.'); }
public function actionInit() { $auth = Yii::$app->authManager; $auth->removeAll(); Console::output('Removing All! RBAC.....'); $manageUser = $auth->createRole('ManageUser'); $manageUser->description = 'สำหรับจัดการข้อมูลผู้ใช้งาน'; $auth->add($manageUser); $author = $auth->createRole('Author'); $author->description = 'สำหรับการเขียนบทความ'; $auth->add($author); $management = $auth->createRole('Management'); $management->description = 'สำหรับจัดการข้อมูลผู้ใช้งานและบทความ'; $auth->add($management); $admin = $auth->createRole('Admin'); $admin->description = 'สำหรับการดูแลระบบ'; $auth->add($admin); $auth->addChild($management, $manageUser); $auth->addChild($management, $author); $auth->addChild($admin, $management); $auth->assign($admin, 1); $auth->assign($management, 2); $auth->assign($author, 3); Console::output('Success! RBAC roles has been added.'); }
public function setExecutable($paths) { foreach ($paths as $executable) { $executable = Yii::getAlias($executable); Console::output("Setting executable: {$executable}"); @chmod($executable, 0755); } }
public function dropTableIfExist($table) { if ($this->tableExist($table)) { return $this->dropTable($table); } else { Console::output('Table "' . $table . '" not found'); } }
public function actionCron() { $time = new \DateTime('now'); foreach ($this->getScheduler()->all() as $task) { if ($this->getScheduler()->handle($task, $time)) { Console::output("Executed " . $task->getKey()); } } }
/** * @inheritdoc */ public function export() { foreach ($this->messages as $message) { if ($message[1] == Logger::LEVEL_ERROR) { Console::error($this->formatMessage($message)); } else { Console::output($this->formatMessage($message)); } } }
public function actionList() { Console::output("Currently waiting exports:"); /** @var ActiveQuery $exportRequests */ $requestsQuery = ExportRequest::find()->where(['is_exported' => 0])->orderBy(['created_at' => SORT_ASC]); foreach ($requestsQuery->each() as $exportRequest) { /** @var ExportRequest $exportRequest */ Console::output("[#" . $exportRequest->id . ": " . $exportRequest->created_at . "] - " . $exportRequest->data_raw); } }
/** * Установка модуля * * - запуск миграций * - запуск установщика модуля * * @param string $module ID модуля */ public function actionModule($packageName, $installationPath = null) { if (!is_dir($installationPath)) { $installationPath = FileHelper::normalizePath(Yii::getAlias('@vendor' . '/' . $packageName), '/'); } $installationFile = $installationPath . '/Install.php'; $basePath = dirname(Yii::getAlias('@vendor')); $io = new Console(); if (file_exists($installationFile)) { $io->output("> installation file: " . $installationFile); $installerClass = (require_once $installationFile); $installer = new $installerClass(array('yiiConsoleApp' => Yii::$app, 'path' => $installationPath, 'name' => $packageName, 'io' => $io, 'migrationPath' => InstallHelper::getMigrationPath($basePath), 'configPath' => InstallHelper::getYiipConfigPath($basePath) . $packageName)); $installer->install(); $io->output("---"); $io->output(""); } else { $io->output("> no installation file"); $io->output(""); } }
/** * 初始化后台用户菜单 */ public function initUserMenu() { Console::output('注册用户模块后台管理菜单 ....'); //用户 Menu::set('user', ['label' => '用户管理', 'url' => ['/admin/user/index'], 'icon' => 'fa-user', 'priority' => 100]); //rbac Menu::set('rbac', ['label' => '角色权限', 'icon' => 'fa-group', 'priority' => 100]); Menu::set('rbac.roles', ['label' => '角色列表', 'url' => ['/admin/role/index'], 'priority' => 101]); Menu::set('rbac.permissions', ['label' => '权限列表', 'url' => ['/admin/permission/index'], 'priority' => 102]); Console::output('注册用户模块后台管理菜单完成 ....'); }
public function install() { parent::install(); if (Console::confirm('Create upload folder?')) { try { $this->createFolder('@webroot/uploads'); Console::output('Folder @webroot/uploads was created'); } catch (\Exception $e) { Console::output($e->getMessage()); } } }
public function actionInit() { $auth = Yii::$app->authManager; $user = $auth->createRole(User::ROLE_USER); $auth->add($user); $admin = $auth->createRole(User::ROLE_ADMINISTRATOR); $auth->add($admin); $auth->addChild($admin, $user); $this->createUser('admin', User::ROLE_ADMINISTRATOR); $this->createUser('user', User::ROLE_USER); Console::output('Success! RBAC roles has been added.'); }
protected function runTasks() { foreach ($this->_tasks as $k => $id) { Console::output(sprintf('Running task "%s" (%d/%d)', $id, $k + 1, count($this->_tasks))); $result = $this->_container->get("tasks.{$id}")->run($this->_container, $this); if ($result === false) { Console::error(sprintf('Task "%s" failed.', $id)); return false; } } return true; }
public function setGeneratedKey($paths) { foreach ($paths as $file) { $file = Yii::getAlias($file); Console::output("Generating keys in {$file}"); $content = file_get_contents($file); $content = preg_replace_callback('/<generated_key>/', function () { $length = 32; $bytes = openssl_random_pseudo_bytes(32, $cryptoStrong); return strtr(substr(base64_encode($bytes), 0, $length), '+/', '_-'); }, $content); file_put_contents($file, $content); } }
/** * @inheritdoc */ public function export() { //iterate over messages foreach ($this->messages as $message) { //fill vars list($text, $level, $category, $timestamp) = $message; //format line if ($this->formatLineCallback != null) { $line = call_user_func($this->formatLineCallback, $this, $text, $level, $category, $timestamp); } else { $line = $this->formatLine($text, $level, $category, $timestamp); } //output Console::output($line); } }
public function actionInit() { $auth = Yii::$app->authManager; $auth->removeAll(); /** * ********** Permission **************************** */ $loginToBackend = $auth->createPermission('loginToBackend'); $loginToBackend->description = 'ยอมให้เข้าใช้งานหลังบ้าน'; $auth->add($loginToBackend); $report1 = $auth->createPermission('Report1'); $report1->description = 'ดูรายงานส่วนที่ 1'; $auth->add($report1); /** * ********** Role **************************** */ $user = $auth->createRole('User'); $auth->add($user); $auth->addChild($user, $report1); $manager = $auth->createRole('Manager'); $auth->add($manager); $provinceial = $auth->createRole('Provinceial'); $auth->add($provinceial); $country = $auth->createRole('Country'); $auth->add($country); $reports = $auth->createRole('Reports'); $auth->add($reports); $administrator = $auth->createRole('Administrator'); $auth->add($administrator); /** * ********** addChild **************************** */ $auth->addChild($manager, $loginToBackend); $auth->addChild($administrator, $user); $auth->addChild($administrator, $manager); $auth->addChild($manager, $user); $auth->addChild($administrator, $provinceial); $auth->addChild($administrator, $country); $auth->addChild($administrator, $reports); /** * ********** Assignment **************************** */ $auth->assign($administrator, 1); $auth->assign($user, 2); $auth->assign($manager, 3); Console::output('Success! RBAC roles has been added.'); }
/** * 用户创建交互 * @param $_model * @return mixed */ private function saveFounderData($_model) { $model = clone $_model; $model->username = Console::prompt('请输入创始人用户名', ['default' => 'admin']); $model->email = Console::prompt('请输入创始人邮箱', ['default' => '*****@*****.**']); $model->password = Console::prompt('请输入创始人密码', ['default' => 'admin']); if (!($user = $model->signup())) { Console::output(Console::ansiFormat("\n输入数据验证错误:", [Console::FG_RED])); foreach ($model->getErrors() as $k => $v) { Console::output(Console::ansiFormat(implode("\n", $v), [Console::FG_RED])); } if (Console::confirm("\n是否重新创建创始人账户:")) { $user = $this->saveFounderData($_model); } } return $user; }
public function execute($command, $params = []) { $command = strtr($command, $params); $exec = $this->getExec(); try { if ($this->getIsVerbose()) { Console::output("Executing {$command}"); } $result = $exec($command); if ($this->getIsVerbose()) { Console::output($result); } return $result; } catch (\RuntimeException $e) { Console::error($e->getMessage()); return false; } }
public function actionGenerate() { $webUrl = Yii::getAlias('@frontendUrl'); // проверка наличия слеша в конце ссылки if (!StringHelper::endsWith($webUrl, '/', false)) { $webUrl .= '/'; } $webPath = Yii::getAlias('@frontend/web/'); // create sitemap $sitemap = new Sitemap($webPath . 'sitemap.xml'); // add some URLs foreach (Article::find()->published()->all() as $item) { $sitemap->addItem($webUrl . 'article/' . $item->slug, time(), Sitemap::DAILY); } // write it $sitemap->write(); // get URLs of sitemaps written $sitemapFileUrls = $sitemap->getSitemapUrls($webUrl); // create sitemap for static files $staticSitemap = new Sitemap($webPath . 'sitemap_static.xml'); // add some URLs $staticSitemap->addItem($webUrl . 'article/index'); $staticSitemap->addItem($webUrl . 'site/contact'); // write it $staticSitemap->write(); // get URLs of sitemaps written $staticSitemapUrls = $staticSitemap->getSitemapUrls($webUrl); // create sitemap index file $index = new Index($webPath . 'sitemap_index.xml'); // add URLs foreach ($sitemapFileUrls as $sitemapUrl) { $index->addSitemap($sitemapUrl); } // add more URLs foreach ($staticSitemapUrls as $sitemapUrl) { $index->addSitemap($sitemapUrl); } // write it $index->write(); Console::output('The sitemap generated successfully.'); }
/** * Show action usage * @param string $required required params separated by comma * @param string $optional optional params separated by comma * @param array $errors errors to output * @throws yii\base\ExitException */ protected function showUsage($required = '', $optional = '', $errors = []) { $description = Yii::t('activeuser_backend', $this->getActionHelp($this->action)); Console::output($description); Console::output(str_pad('', mb_strlen($description), '-')); $paramsString = []; if (!empty($required)) { foreach (explode(',', $required) as $param) { $paramsString[] = '<' . trim($param) . '>'; } } if (!empty($optional)) { foreach (explode(',', $optional) as $param) { $paramsString[] = '[' . trim($param) . ']'; } } Console::output(Yii::t('activeuser_backend', 'Usage') . ': ' . Console::ansiFormat('yii ' . $this->id . "/" . $this->action->id . ' ' . implode(' ', $paramsString), [Console::BOLD])); Console::output(); if (!empty($errors)) { $this->showErrors($errors); } yii::$app->end(); }
public function actionInit() { $auth = Yii::$app->authManager; $auth->removeAll(); // own model rule $ownModelRule = new OwnModel(); $auth->add($ownModelRule); // add the rule $shopProfileOwnerRule = new ShopProfileOwnerRule(); $auth->add($shopProfileOwnerRule); $updateOwnBankProfile = $auth->createPermission('isProfileOwner'); $updateOwnBankProfile->ruleName = $updateOwnBankProfile->name; $auth->add($updateOwnBankProfile); $user = $auth->createRole(User::ROLE_USER); $auth->add($user); $shop = $auth->createRole(User::ROLE_SHOP); $auth->add($shop); $auth->addChild($shop, $user); $auth->addChild($shop, $updateOwnBankProfile); $content = $auth->createRole(User::ROLE_CONTENT); $auth->add($content); $auth->addChild($content, $user); $admin = $auth->createRole(User::ROLE_ADMIN); $auth->add($admin); $auth->addChild($admin, $user); $auth->addChild($admin, $content); $auth->addChild($admin, $shop); $loginToBackend = $auth->createPermission('loginToBackend'); $auth->add($loginToBackend); $auth->addChild($user, $loginToBackend); $auth->assign($admin, 1); $auth->assign($content, 2); $auth->assign($user, 3); $auth->assign($shop, 4); Console::output('Success! RBAC roles has been added.'); }
/** * Создает внешние ключи и инициализирует хранилище в базе */ public function actionInit() { Console::output('Create FK'); $this->getIStore()->initStore(); Console::output("Add stores\n"); foreach ($this->getIStore()->models as $model) { $trans = \Yii::$app->db->beginTransaction(Transaction::REPEATABLE_READ); try { foreach ($model['fields'] as $field => $opts) { $store = ImageStore::getStore($model['class'], $field); } $trans->commit(); Console::output($this->getClassDoc($model)); } catch (Exception $e) { $trans->rollBack(); Console::output($e); } } $i = new Image(); $u = new User(); Console::output('Image:' . VarDumper::dumpAsString($i->imageFields)); Console::output('User:' . VarDumper::dumpAsString($u->imageFields)); Console::output($i->iStore->getEmptyFileName(1)); }
/** * @throws \yii\base\ExitException */ public function end() { Console::output('Exiting queue listener'); Yii::$app->end(); }
public static function hint($msg) { $msg = Console::ansiFormat($msg, [Console::FG_BLUE, Console::BOLD]); Console::output($msg); }
public function download() { Console::output('Downloading composer...'); return $this->server->execute('cd :path && :phpBin -r "readfile(\'https://getcomposer.org/installer\');" | :phpBin -- --filename=:composer', [':path' => $this->path, ':phpBin' => $this->server->phpBin, ':composer' => $this->composer]); }
/** * @param $arg * @return bool|int|mixed */ public function stdout($arg) { /** @var Controller $controller */ $controller = Yii::$app->controller; if ($controller instanceof Controller) { return call_user_func_array([$controller, 'stdout'], func_get_args()); } return Console::output($arg); }