Feat: Implement password reset
This commit is contained in:
@@ -60,6 +60,39 @@ class ApiClient
|
||||
public function updateProfile(): void
|
||||
{}
|
||||
|
||||
public function resetPassword(string $email): BaseResponse
|
||||
{
|
||||
$data = [
|
||||
'anfrage' => [
|
||||
'user' => $this->config['bpn_username'],
|
||||
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], 'KUNDENKONTO'),
|
||||
'satz' => ['@typ' => 'KUNDENKONTO'],
|
||||
'art' => 'Passwort_Anfrage',
|
||||
'email' => $email,
|
||||
],
|
||||
];
|
||||
|
||||
$body = $this
|
||||
->serializer
|
||||
->serialize($data, 'xml')
|
||||
;
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('GET', $this->config['bpn_url'], [
|
||||
'query' => [
|
||||
'operation' => $body,
|
||||
]
|
||||
]);
|
||||
|
||||
$xml = $response->getContent();
|
||||
|
||||
return $this->responseParser->parseXmlString($xml);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
throw new ApiClientException($e->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
*/
|
||||
|
||||
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<div class="w-full h-screen flex flex-col items-center justify-center px-4">
|
||||
<div class="w-full max-w-sm">
|
||||
<h1 class="text-4xl font-bold text-gray-900 mb-6">
|
||||
MyE&P Teams
|
||||
</h1>
|
||||
{{ form_start(form) }}
|
||||
<div class="mb-6">
|
||||
<label for="username" class="block text-sm font-semibold leading-6 text-gray-900">
|
||||
E-Mail:
|
||||
</label>
|
||||
{{ form_widget(form.email) }}
|
||||
{{ form_errors(form.email) }}
|
||||
</div>
|
||||
<button type="submit" class="inline-flex justify-center rounded-lg text-sm font-semibold py-2.5 px-4 bg-slate-900 text-white hover:bg-slate-700 w-full">
|
||||
Passwort zurückseten
|
||||
</button>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user