-
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.
refactor!: Removing reset password service, adding login link, refact…
…oring routes
- Loading branch information
1 parent
9e0b97c
commit 84c30ec
Showing
30 changed files
with
275 additions
and
404 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
<?php | ||
|
||
namespace Dontdrinkandroot\BridgeBundle\Config; | ||
|
||
use Dontdrinkandroot\BridgeBundle\Command\User\EditCommand; | ||
use Dontdrinkandroot\BridgeBundle\Controller\Security\LoginLink\CheckAction; | ||
use Dontdrinkandroot\BridgeBundle\Controller\Security\LoginAction; | ||
use Dontdrinkandroot\BridgeBundle\Controller\Security\LoginLink\RequestAction; | ||
use Dontdrinkandroot\BridgeBundle\Repository\User\UserRepository; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
use function Symfony\Component\DependencyInjection\Loader\Configurator\param; | ||
|
||
return function (ContainerConfigurator $configurator): void { | ||
$services = $configurator->services(); | ||
|
||
$services->set(RequestAction::class) | ||
->autoconfigure() | ||
->autowire() | ||
->tag('controller.service_arguments'); | ||
|
||
$services->set(CheckAction::class) | ||
->autoconfigure() | ||
->autowire() | ||
->tag('controller.service_arguments'); | ||
}; |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
<?php | ||
|
||
namespace Dontdrinkandroot\BridgeBundle\Controller\Security\LoginLink; | ||
|
||
use Dontdrinkandroot\BridgeBundle\Model\Container\RouteName; | ||
use LogicException; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
class CheckAction extends AbstractController | ||
{ | ||
public function __invoke(): never | ||
{ | ||
throw new LogicException('This code should never be reached'); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
namespace Dontdrinkandroot\BridgeBundle\Controller\Security\LoginLink; | ||
|
||
use Dontdrinkandroot\BridgeBundle\Model\Container\RouteName; | ||
use Dontdrinkandroot\BridgeBundle\Repository\User\UserRepository; | ||
use Dontdrinkandroot\BridgeBundle\Service\Mail\MailServiceInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\Form\Extension\Core\Type\EmailType; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Mime\Address; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface; | ||
use Symfony\Component\Translation\TranslatableMessage; | ||
|
||
class RequestAction extends AbstractController | ||
{ | ||
public function __construct( | ||
private readonly LoginLinkHandlerInterface $loginLinkHandler, | ||
private readonly TokenStorageInterface $tokenStorage, | ||
private readonly UserRepository $userRepository, | ||
private readonly MailServiceInterface $mailService, | ||
) { | ||
} | ||
|
||
public function __invoke(Request $request): Response | ||
{ | ||
if (null !== ($user = $this->tokenStorage->getToken()?->getUser())) { | ||
return $this->redirectToRoute('app.index'); | ||
} | ||
|
||
$form = $this->createFormBuilder() | ||
->add('email', EmailType::class) | ||
->getForm(); | ||
|
||
$success = false; | ||
$form->handleRequest($request); | ||
if ($form->isSubmitted() && $form->isValid()) { | ||
$email = $form->getData()['email']; | ||
$user = $this->userRepository->findOneByEmail($email); | ||
if (null !== $user) { | ||
$loginLinkDetails = $this->loginLinkHandler->createLoginLink($user); | ||
$loginLink = $loginLinkDetails->getUrl(); | ||
$this->mailService->sendMailMarkdownTemplate( | ||
to: new Address($user->email), | ||
subject: 'Login Link', | ||
template: '@DdrBridge/Security/login_link.mail.md.twig', | ||
templateParameters: [ | ||
'user' => $user, | ||
'link' => $loginLink, | ||
] | ||
); | ||
} | ||
$this->addFlash( | ||
'success', | ||
new TranslatableMessage('login_link.flash.success', [], 'ddr_security') | ||
); | ||
$success = true; | ||
} | ||
|
||
return $this->render('@DdrBridge/Security/request_login_link.html.twig', [ | ||
'form' => $form->createView(), | ||
'success' => $success, | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.