-
-
Notifications
You must be signed in to change notification settings - Fork 112
fix(user, composer): removing martial status, dependencies (fixes #1587) #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MrKrasnov
wants to merge
13
commits into
OpenVK:master
Choose a base branch
from
MrKrasnov:dev-1587
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
17905c0
FIX incorrect php version for composer.json We use php 8.2
MrKrasnov 6c38315
Added CLI command for generate test users
MrKrasnov 63dd14d
Fixed: Removing marital status user
MrKrasnov 8d9ca1f
Changed set last name for cli
MrKrasnov f202690
Changed placeholder for edit marital status
MrKrasnov 950bd92
build(deps): install fakerphp/faker
MrKrasnov 02681fb
feat(cli): use Faker to generate user data
MrKrasnov cdc741f
style(cli): fix php-cs-fixer formatting
MrKrasnov bb53df7
revert(composer.json): revert php version
MrKrasnov 9377e72
revert (locales): removed locales key "marital_status_user_id"
MrKrasnov b21d088
refactor (edit): added param trim backslash for getURL
MrKrasnov c14ef60
chore (bootstrap): changed text for error incompatible php version
MrKrasnov 17f3ecb
revert(bootstrap): reverted text for error incompatible php version
MrKrasnov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace openvk\CLI; | ||
|
|
||
| use Chandler\Security\User as ChandlerUser; | ||
| use Faker\Factory as FakerFactory; | ||
| use openvk\Web\Models\Entities\User; | ||
| use openvk\Web\Models\Exceptions\InvalidUserNameException; | ||
| use openvk\Web\Util\Validator; | ||
| use Random\RandomException; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
|
||
| class GenerateUsersCommand extends Command | ||
| { | ||
| protected static $defaultName = "generate-users"; | ||
| protected function configure(): void | ||
| { | ||
| $this->setDescription("Generate test user accounts for development") | ||
| ->addOption( | ||
| "count", | ||
| "c", | ||
| InputOption::VALUE_REQUIRED, | ||
| "Number of users to create", | ||
| 1 | ||
| ); | ||
| } | ||
|
|
||
| //Duplicate the logic from the Web/Presenters/AuthPresenter.php class | ||
| /** | ||
| * @throws RandomException | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| $io = new SymfonyStyle($input, $output); | ||
| $faker = FakerFactory::create("en_US"); | ||
| $count = (int) $input->getOption("count"); | ||
|
|
||
| if ($count < 1) { | ||
| $io->error("Count must be at least 1."); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| $created = []; | ||
|
|
||
| for ($i = 1; $i <= $count; $i++) { | ||
| $email = $faker->unique()->safeEmail(); | ||
| $password = $this->generatePassword(); | ||
|
|
||
| try { | ||
| $user = new User(); | ||
| $user->setFirst_Name($faker->firstName()); | ||
| $user->setLast_Name($faker->lastName()); | ||
| $user->setSex(0); | ||
| $user->setEmail($email); | ||
| $user->setSince(date("Y-m-d H:i:s")); | ||
| $user->setRegistering_Ip("127.0.0.1"); | ||
| $user->setBirthday($faker->dateTimeBetween("-60 years", "-18 years")->getTimestamp()); | ||
| $user->setActivated(1); | ||
| } catch (InvalidUserNameException $ex) { | ||
| $io->error("Failed to set name for user #{$i}: " . $ex->getMessage()); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| $chUser = ChandlerUser::create($email, $password); | ||
| if (!$chUser) { | ||
| $io->error("Failed to create Chandler user for {$email}"); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| $user->setUser($chUser->getId()); | ||
| $user->save(false); | ||
|
|
||
| $created[] = [ | ||
| "id" => $user->getId(), | ||
| "email" => $email, | ||
| "password" => $password, | ||
| "url" => "/id" . $user->getId(), | ||
| ]; | ||
| } | ||
|
|
||
| $io->success("Created " . count($created) . " user(s)."); | ||
|
|
||
| $rows = array_map(static fn(array $u): array => [ | ||
| $u["id"], | ||
| $u["email"], | ||
| $u["password"], | ||
| $u["url"], | ||
| ], $created); | ||
|
|
||
| $io->table(["ID", "Email", "Password", "Profile URL"], $rows); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
|
|
||
| /** | ||
| * @throws RandomException | ||
| */ | ||
| private function generatePassword(): string | ||
| { | ||
| do { | ||
| $password = "OvK" . bin2hex(random_bytes(4)) . "A1"; | ||
| } while (!Validator::i()->passwordStrong($password)); | ||
|
|
||
| return $password; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.