Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions sources/AppBundle/Association/UserMembership/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use AppBundle\MembershipFee\Entity\Cotisation;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;

class UserService
{
Expand Down Expand Up @@ -64,10 +65,15 @@ public function resetPassword(User $user): void
*/
public function resetPasswordForEmail($email): void
{
$user = $this->userRepository->loadUserByEmailOrAlternateEmail($email);
if (null !== $user) {
$this->resetPassword($user);
try {
$user = $this->userRepository->loadUserByEmailOrAlternateEmail($email);
} catch (UserNotFoundException) {
// Email inconnu : on s'arrête sans le signaler, pour ne pas révéler quels
// emails correspondent à un compte.
return;
}

$this->resetPassword($user);
}

public function sendWelcomeEmail(User $user): bool
Expand Down
3 changes: 0 additions & 3 deletions sources/AppBundle/Controller/Auth/LostPasswordAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public function __invoke(Request $request): Response

return $this->view->render('site/auth/lost_password.html.twig', [
'form' => $form->createView(),
'title' => 'Mot de passe perdu',
'page' => 'motdepasse_perdu',
'class' => 'panel-page',
]);
}
}
65 changes: 34 additions & 31 deletions templates/site/auth/lost_password.html.twig
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
{% extends 'admin/association/membership/_base.html.twig' %}

{% block page_title %}{% endblock %}

{% block page_container_extra_classes %}remove-min-height-from-container-id{% endblock %}

{% block page_content %}

<div class="afup-form afup-form--miniform">
{{ form_start(form) }}
<fieldset>
<legend>Mot de passe perdu</legend>
<div class="afup-form-container">
<div>
<p>
Indiquez votre email ici. Si un compte correspond à cet email, vous recevrez un nouveau mot de passe.
</p>
</div>
<div>
{{ form_label(form.email) }}
{{ form_widget(form.email) }}
</div>
<div>
{{ form_widget(form.submit, {attr: {"class": "button button--call-to-action"}}) }}
</div>
<div>
<p>
<a href="{{ url('app_login') }}">Retour au formulaire de connexion</a>
</p>
</div>
{% extends 'layouts/site.html.twig' %}
{% form_theme form 'form_themes/tailwind.html.twig' %}

{% block title %}Mot de passe perdu - AFUP{% endblock %}

{% block content %}

<div class="container mx-auto flex flex-col items-center px-4 my-5 gap-4">
<h1 class="font-titre font-normal text-5xl text-afup-800 text-center">Mot de passe perdu</h1>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas besoin de reset l'épaisseur du texte ici.

Suggested change
<h1 class="font-titre font-normal text-5xl text-afup-800 text-center">Mot de passe perdu</h1>
<h1 class="font-titre text-5xl text-afup-800 text-center">Mot de passe perdu</h1>

<p class="font-sans font-normal text-base text-neutre-700 text-center max-w-2xl">

@Mopolo Mopolo Aug 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil il y a trop de classes ici.

Suggested change
<p class="font-sans font-normal text-base text-neutre-700 text-center max-w-2xl">
<p class="text-neutre-700 text-center max-w-2xl">

Indiquez votre email ici. Si un compte correspond à cet email, vous recevrez un nouveau mot de passe.
</p>

{{ form_start(form, {attr: {class: 'w-full sm:w-200'}}) }}

<twig:Card class="flex flex-col gap-8 px-6 py-12 sm:px-28 sm:py-12 my-5 sm:mb-10 w-full">

{# Le contrôleur pose un flash 'notice' : c'est le seul retour visible de la demande,
et layouts/site.html.twig n'affiche pas les flashs. #}
{% for message in app.flashes('notice') %}
<twig:Alert type="success" class="w-full">{{ message }}</twig:Alert>
{% endfor %}

{{ form_errors(form) }}
{{ form_row(form.email, {label: 'Email', attr: {autofocus: true}}) }}

<div class="flex flex-col-reverse sm:flex-row items-center justify-between gap-4 border-t-2 border-neutre-300 pt-5">
<p class="font-sans font-normal text-sm text-neutre-700 whitespace-nowrap">

@Mopolo Mopolo Aug 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p class="font-sans font-normal text-sm text-neutre-700 whitespace-nowrap">
<p class="text-sm text-neutre-700 whitespace-nowrap">

<a href="{{ path('app_login') }}" class="text-afup-500 underline hover:no-underline">Retour à la connexion</a>
</p>
{{ form_widget(form.submit) }}
</div>

</fieldset>
</twig:Card>

{{ form_end(form) }}
</div>

{% endblock %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un test avec autant de mocks ne me parait pas une bonne idée.

Ce serait mieux, soit d'avoir un test behat, soit de s'en passer.

Là les seuls assertions sont sur des mocks donc on se retrouve juste avec une copie de code, peu d'intérêt et cela rend le test beaucoup trop lié à du code privé.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace AppBundle\Tests\Association\UserMembership;

use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\Association\UserMembership\UserService;
use AppBundle\Email\Mailer\Mailer;
use AppBundle\MembershipFee\MembershipFeeService;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;

class UserServiceTest extends TestCase
{
/**
* Le dépôt lève une UserNotFoundException quand aucun compte ne correspond : la demande de
* nouveau mot de passe doit s'arrêter silencieusement, sans révéler que l'email est inconnu.
*/
#[Test]
public function itIgnoresAPasswordResetForAnUnknownEmail(): void
{
$userRepository = $this->createMock(UserRepository::class);
$userRepository
->method('loadUserByEmailOrAlternateEmail')
->willThrowException(new UserNotFoundException());
$userRepository->expects($this->never())->method('save');

$mailer = $this->createMock(Mailer::class);
$mailer->expects($this->never())->method('send');

$userService = new UserService(
$userRepository,
$mailer,
$this->createStub(UrlGeneratorInterface::class),
$this->createStub(MembershipFeeService::class),
$this->createStub(UserPasswordHasherInterface::class),
);

$userService->resetPasswordForEmail('aucun-compte@example.invalid');
}
}
Loading