Feat: Implement password reset
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Security;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\ApiClientException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
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\Routing\Annotation\Route;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
class PasswordResetController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly ApiClient $apiClient, private readonly LoggerInterface $logger)
|
||||
{}
|
||||
|
||||
#[Route('/password-reset', name: 'app_security_password_reset')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$form = $this
|
||||
->createFormBuilder()
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'E-Mail',
|
||||
'constraints' => [
|
||||
new NotBlank([
|
||||
'message' => 'Bitte angeben',
|
||||
]),
|
||||
new Email([
|
||||
'mode' => 'strict',
|
||||
'message' => 'Ungültige E-Mail-Adresse',
|
||||
]),
|
||||
],
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$email = $form->get('email')->getData();
|
||||
|
||||
try {
|
||||
$this
|
||||
->apiClient
|
||||
->resetPassword($email)
|
||||
;
|
||||
} catch (ApiClientException $e) {
|
||||
}
|
||||
|
||||
$this->addFlash('success', 'Passwort Reset wurde angefordert');
|
||||
|
||||
$this->logger->info('Password reset', [
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_security_login');
|
||||
}
|
||||
|
||||
return $this->render('security/password_reset.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user