Skip to content

Commit

Permalink
refactor: Removed base RozierApp class when possible, added LogTrail …
Browse files Browse the repository at this point in the history
…service for publishing message in session and logger
  • Loading branch information
roadiz-ci committed Dec 3, 2024
1 parent 297df80 commit 4440da7
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 582 deletions.
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"ext-json": "*",
"ext-mbstring": "*",
"api-platform/core": "~3.3.11",
"doctrine/annotations": "^1.0",
"doctrine/annotations": "^2.0",
"doctrine/doctrine-bundle": "^2.8.1",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "~2.19.0",
"doctrine/orm": "~2.20.0",
"gedmo/doctrine-extensions": "^3.16.1",
"inlinestyle/inlinestyle": "~1.2.7",
"james-heinrich/getid3": "^1.9",
Expand All @@ -52,18 +52,17 @@
"roadiz/models": "2.4.x-dev",
"roadiz/nodetype-contracts": "~1.1.2",
"roadiz/random": "2.4.x-dev",
"rollerworks/password-common-list": "^0.2.0",
"rollerworks/password-strength-bundle": "^2.2",
"rollerworks/password-common-list": "^0.3.0",
"rollerworks/password-strength-bundle": "^3.0",
"scienta/doctrine-json-functions": "^4.2",
"sensio/framework-extra-bundle": "^6.1",
"solarium/solarium": "^6.0.4",
"symfony-cmf/routing-bundle": "^3.0.2",
"solarium/solarium": "^6.3.6",
"symfony-cmf/routing-bundle": "^3.1.0",
"symfony/asset": "6.4.*",
"symfony/cache": "6.4.*",
"symfony/console": "6.4.*",
"symfony/dotenv": "6.4.*",
"symfony/expression-language": "6.4.*",
"symfony/flex": "^2.2.3",
"symfony/flex": "^2.4.7",
"symfony/form": "6.4.*",
"symfony/framework-bundle": "6.4.*",
"symfony/http-client": "6.4.*",
Expand Down
7 changes: 6 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,12 @@ services:
arguments: ['%kernel.project_dir%']
public: true

RZ\Roadiz\Random\PasswordGenerator: ~
RZ\Roadiz\Random\PasswordGeneratorInterface:
class: RZ\Roadiz\Random\PasswordGenerator
RZ\Roadiz\Random\SaltGeneratorInterface:
class: RZ\Roadiz\Random\SaltGenerator
RZ\Roadiz\Random\TokenGeneratorInterface:
class: RZ\Roadiz\Random\TokenGenerator

JMS\Serializer\Construction\ObjectConstructorInterface:
alias: RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\ObjectConstructor
Expand Down
13 changes: 10 additions & 3 deletions src/Console/UsersPasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\CoreBundle\Entity\User;
use RZ\Roadiz\Random\PasswordGenerator;
use RZ\Roadiz\Random\PasswordGeneratorInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -16,7 +16,7 @@
final class UsersPasswordCommand extends UsersCommand
{
public function __construct(
private readonly PasswordGenerator $passwordGenerator,
private readonly PasswordGeneratorInterface $passwordGenerator,
ManagerRegistry $managerRegistry,
?string $name = null,
) {
Expand All @@ -31,6 +31,11 @@ protected function configure(): void
'username',
InputArgument::REQUIRED,
'Username'
)->addOption(
'length',
'l',
InputArgument::OPTIONAL,
default: 16,
);
}

Expand All @@ -49,7 +54,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$confirmation
)
) {
$user->setPlainPassword($this->passwordGenerator->generatePassword(12));
$user->setPlainPassword($this->passwordGenerator->generatePassword(
(int) $input->getOption('length')
));
$this->managerRegistry->getManagerForClass(User::class)->flush();
$io->success('A new password was regenerated for '.$name.': '.$user->getPlainPassword());

Expand Down
13 changes: 5 additions & 8 deletions src/Security/Authentication/RoadizAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ abstract class RoadizAuthenticator extends AbstractLoginFormAuthenticator
{
use TargetPathTrait;

public const LOGIN_ROUTE = 'loginPage';

public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
protected readonly UrlGeneratorInterface $urlGenerator,
private readonly ManagerRegistry $managerRegistry,
private readonly LoggerInterface $logger,
private readonly string $usernamePath = 'username',
Expand Down Expand Up @@ -69,7 +67,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
return new RedirectResponse($targetPath);
}

return new RedirectResponse($this->urlGenerator->generate('adminHomePage'));
return new RedirectResponse($this->getDefaultSuccessPath($request));
}

public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response
Expand All @@ -84,10 +82,9 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
return parent::onAuthenticationFailure($request, $exception);
}

protected function getLoginUrl(Request $request): string
{
return $this->urlGenerator->generate(self::LOGIN_ROUTE);
}
abstract protected function getLoginUrl(Request $request): string;

abstract protected function getDefaultSuccessPath(Request $request): string;

/**
* @return array<'username'|'password', string>
Expand Down
Loading

0 comments on commit 4440da7

Please sign in to comment.