// TODO: Podpora pro uziv. role use vBuilder\Security\User, vBuilder\Utils\CliArgsParser, vBuilder\Utils\Strings, vBuilder\Security\IdentityFactory; $container = (require __DIR__ . '/bootstrap.php'); // ----------------------------------------------------------------------------- // ARGUMENTS // ----------------------------------------------------------------------------- $args = new CliArgsParser(); $args->addOption('password', 'secret', 'user password', NULL)->setNumRequiredArgs(1, 1)->setArgumentHelp('username'); if (!$args->parse()) { echo "\n" . $args->getErrorMsg() . "\n\n"; $args->printUsage(); echo "\n"; exit; } list($user) = $args->getArguments(); $password = $args->get('password') !== FALSE ? $args->get('password') : Strings::randomHumanToken(); // ----------------------------------------------------------------------------- // INIT // ----------------------------------------------------------------------------- $db = $container->getByType('DibiConnection'); $authn = $container->user->getAuthenticator(User::AUTHN_METHOD_PASSWORD, User::AUTHN_SOURCE_DATABASE); $rolesTable = $authn->identityFactory->getTableName(IdentityFactory::TABLE_ROLES); $roles = array('Administrator'); // ----------------------------------------------------------------------------- // DB // ----------------------------------------------------------------------------- $data = array($authn->getColumn($authn::USERNAME) => $user, $authn->getColumn($authn::PASSWORD) => $authn->getPasswordHasher()->hashPassword($password)); try { $db->query("INSERT INTO %n", $authn->tableName, $data); $uid = $db->getInsertId(); echo "ID noveho uzivatele: {$uid}\n";
<?php use vBuilder\Utils\CliArgsParser, vBuilder\Utils\FileSystem; // ----------------------------------------------------------------------------- // INIT // ----------------------------------------------------------------------------- $container = (require __DIR__ . '/bootstrap.php'); $tm = $container->getByType('vBuilder\\Database\\TableManager'); $db = $container->getByType('DibiConnection'); $workPath = realpath(getcwd()); // ----------------------------------------------------------------------------- // ARGUMENTS // ----------------------------------------------------------------------------- $args = new CliArgsParser(); $args->addSwitch('data', 'Dump data')->addSwitch('help', 'Help'); if (!$args->parse() || $args->get('help')) { if ($args->get('help')) { echo "\n"; } else { echo "\n" . $args->getErrorMsg() . "\n\n"; } $args->printUsage(); echo "\n"; exit; } // ----------------------------------------------------------------------------- // ROUTINES // ----------------------------------------------------------------------------- /** * @param DibiConnection * @param string table name