-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
542 additions
and
144 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20230803131631 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Drop useless expired and credentials_expired fields from users table.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP INDEX IDX_1483A5E9194FED4B ON users'); | ||
$this->addSql('ALTER TABLE users DROP expired, DROP credentials_expired'); | ||
$this->addSql('CREATE INDEX idx_users_username ON users (username)'); | ||
$this->addSql('CREATE INDEX idx_users_email ON users (email)'); | ||
$this->addSql('CREATE INDEX idx_users_credentials_expires_at ON users (credentials_expires_at)'); | ||
$this->addSql('CREATE INDEX idx_users_password_requested_at ON users (password_requested_at)'); | ||
$this->addSql('CREATE INDEX idx_users_last_login ON users (last_login)'); | ||
$this->addSql('CREATE INDEX idx_users_locked ON users (locked)'); | ||
$this->addSql('CREATE INDEX IDX_1483A5E98B8E8428 ON users (created_at)'); | ||
$this->addSql('CREATE INDEX IDX_1483A5E943625D9F ON users (updated_at)'); | ||
$this->addSql('ALTER TABLE users RENAME INDEX idx_1483a5e950f9bb84 TO idx_users_enabled'); | ||
$this->addSql('ALTER TABLE users RENAME INDEX idx_1483a5e9f9d83e2 TO idx_users_expires_at'); | ||
$this->addSql('ALTER TABLE users RENAME INDEX idx_1483a5e94180c698 TO idx_users_locale'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP INDEX idx_users_username ON users'); | ||
$this->addSql('DROP INDEX idx_users_email ON users'); | ||
$this->addSql('DROP INDEX idx_users_credentials_expires_at ON users'); | ||
$this->addSql('DROP INDEX idx_users_password_requested_at ON users'); | ||
$this->addSql('DROP INDEX idx_users_last_login ON users'); | ||
$this->addSql('DROP INDEX idx_users_locked ON users'); | ||
$this->addSql('DROP INDEX IDX_1483A5E98B8E8428 ON users'); | ||
$this->addSql('DROP INDEX IDX_1483A5E943625D9F ON users'); | ||
$this->addSql('ALTER TABLE users ADD expired TINYINT(1) DEFAULT 0 NOT NULL, ADD credentials_expired TINYINT(1) DEFAULT 0 NOT NULL'); | ||
$this->addSql('CREATE INDEX IDX_1483A5E9194FED4B ON users (expired)'); | ||
$this->addSql('ALTER TABLE users RENAME INDEX idx_users_locale TO IDX_1483A5E94180C698'); | ||
$this->addSql('ALTER TABLE users RENAME INDEX idx_users_enabled TO IDX_1483A5E950F9BB84'); | ||
$this->addSql('ALTER TABLE users RENAME INDEX idx_users_expires_at TO IDX_1483A5E9F9D83E2'); | ||
} | ||
|
||
public function isTransactional(): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains 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 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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Console; | ||
|
||
use RZ\Roadiz\CoreBundle\Entity\User; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class UsersExpireCommand extends UsersCommand | ||
{ | ||
protected function configure(): void | ||
{ | ||
$this->setName('users:expire') | ||
->setDescription('Set a user account expiration date') | ||
->addArgument( | ||
'username', | ||
InputArgument::REQUIRED, | ||
'Username' | ||
) | ||
->addArgument( | ||
'expiry', | ||
InputArgument::OPTIONAL, | ||
'Expiration date and time (Y-m-d H:i:s)' | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
$name = $input->getArgument('username'); | ||
$user = $this->getUserForInput($input); | ||
$expirationDate = new \DateTime($input->getArgument('expiry') ?? 'now'); | ||
|
||
$question = sprintf( | ||
'<question>Do you really want to set user “%s” expiration date on %s?</question>', | ||
$user->getUsername(), | ||
$expirationDate->format('c') | ||
); | ||
$confirmation = new ConfirmationQuestion($question, false); | ||
if ( | ||
!$input->isInteractive() || $io->askQuestion( | ||
$confirmation | ||
) | ||
) { | ||
$user->setExpiresAt($expirationDate); | ||
$this->managerRegistry->getManagerForClass(User::class)->flush(); | ||
$io->success('User “' . $name . '” expiration date was set on ' . $expirationDate->format('c') . '.'); | ||
return 0; | ||
} else { | ||
$io->warning('User “' . $name . '” was not updated.'); | ||
return 1; | ||
} | ||
} | ||
} |
This file contains 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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Console; | ||
|
||
use RZ\Roadiz\CoreBundle\Entity\User; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class UsersLockCommand extends UsersCommand | ||
{ | ||
protected function configure(): void | ||
{ | ||
$this->setName('users:lock') | ||
->setDescription('Lock a user account') | ||
->addArgument( | ||
'username', | ||
InputArgument::REQUIRED, | ||
'Username' | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
$name = $input->getArgument('username'); | ||
$user = $this->getUserForInput($input); | ||
|
||
$confirmation = new ConfirmationQuestion( | ||
'<question>Do you really want to lock user “' . $user->getUsername() . '”?</question>', | ||
false | ||
); | ||
if ( | ||
!$input->isInteractive() || $io->askQuestion( | ||
$confirmation | ||
) | ||
) { | ||
$user->setLocked(true); | ||
$this->managerRegistry->getManagerForClass(User::class)->flush(); | ||
$io->success('User “' . $name . '” locked.'); | ||
return 0; | ||
} else { | ||
$io->warning('User “' . $name . '” was not locked.'); | ||
return 1; | ||
} | ||
} | ||
} |
Oops, something went wrong.