|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Api\Field\Mutation; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Model\Log; |
|
8
|
|
|
use Application\Model\User; |
|
9
|
|
|
use Application\Repository\LogRepository; |
|
10
|
|
|
use Application\Repository\UserRepository; |
|
11
|
|
|
use Application\Service\MessageQueuer; |
|
12
|
|
|
use Ecodev\Felix\Api\ExceptionWithoutMailLogging; |
|
13
|
|
|
use Ecodev\Felix\Api\Field\FieldInterface; |
|
14
|
|
|
use Ecodev\Felix\Service\Mailer; |
|
15
|
|
|
use GraphQL\Type\Definition\Type; |
|
16
|
|
|
use Mezzio\Session\SessionInterface; |
|
17
|
|
|
|
|
18
|
|
|
abstract class RequestPasswordReset implements FieldInterface |
|
19
|
|
|
{ |
|
20
|
4 |
|
public static function build(): iterable |
|
21
|
|
|
{ |
|
22
|
1 |
|
yield 'requestPasswordReset' => fn () => [ |
|
23
|
1 |
|
'type' => Type::nonNull(Type::boolean()), |
|
24
|
1 |
|
'description' => 'Request to send an email to reset the password for the given user. It will **always** return a successful response, even if the user is not found. Returns `true` if the email was sent to the family owner.', |
|
25
|
1 |
|
'args' => [ |
|
26
|
1 |
|
'login' => Type::nonNull(Type::string()), |
|
27
|
1 |
|
], |
|
28
|
1 |
|
'resolve' => function ($root, array $args, SessionInterface $session): bool { |
|
29
|
|
|
global $container; |
|
30
|
|
|
|
|
31
|
4 |
|
_log()->info(LogRepository::REQUEST_PASSWORD_RESET); |
|
32
|
|
|
|
|
33
|
|
|
/** @var LogRepository $logRepository */ |
|
34
|
4 |
|
$logRepository = _em()->getRepository(Log::class); |
|
35
|
4 |
|
if ($logRepository->requestPasswordResetOften()) { |
|
36
|
|
|
throw new ExceptionWithoutMailLogging('Trop de tentatives de changement de mot de passe. Veuillez réessayer plus tard.'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** @var Mailer $mailer */ |
|
40
|
4 |
|
$mailer = $container->get(Mailer::class); |
|
41
|
|
|
|
|
42
|
|
|
/** @var MessageQueuer $messageQueuer */ |
|
43
|
4 |
|
$messageQueuer = $container->get(MessageQueuer::class); |
|
44
|
|
|
|
|
45
|
|
|
/** @var UserRepository $repository */ |
|
46
|
4 |
|
$repository = _em()->getRepository(User::class); |
|
47
|
|
|
|
|
48
|
|
|
/** @var null|User $user */ |
|
49
|
4 |
|
$user = $repository->getOneByLoginOrEmail($args['login']); |
|
50
|
|
|
|
|
51
|
4 |
|
if ($user) { |
|
52
|
3 |
|
$message = $messageQueuer->queueResetPassword($user); |
|
53
|
|
|
|
|
54
|
3 |
|
if ($message) { |
|
55
|
3 |
|
$mailer->sendMessageAsync($message); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
3 |
|
return $messageQueuer->wasToFamilyOwner(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
return false; |
|
62
|
1 |
|
}, |
|
63
|
1 |
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|