1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Api\Field\Mutation; |
6
|
|
|
|
7
|
|
|
use Application\Api\Field\FieldInterface; |
8
|
|
|
use Application\Api\Scalar\LoginType; |
9
|
|
|
use Application\DBAL\Types\RelationshipType; |
10
|
|
|
use Application\Model\User; |
11
|
|
|
use Application\Repository\UserRepository; |
12
|
|
|
use Application\Service\Mailer; |
13
|
|
|
use GraphQL\Type\Definition\Type; |
14
|
|
|
use Zend\Expressive\Session\SessionInterface; |
15
|
|
|
|
16
|
|
|
abstract class RequestPasswordReset implements FieldInterface |
17
|
|
|
{ |
18
|
3 |
|
public static function build(): array |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
1 |
|
'name' => 'requestPasswordReset', |
22
|
1 |
|
'type' => Type::nonNull(_types()->get('Relationship')), |
23
|
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.', |
24
|
|
|
'args' => [ |
25
|
1 |
|
'login' => Type::nonNull(_types()->get(LoginType::class)), |
26
|
|
|
], |
27
|
|
|
'resolve' => function ($root, array $args, SessionInterface $session): string { |
|
|
|
|
28
|
3 |
|
global $container; |
29
|
|
|
/** @var Mailer $mailer */ |
30
|
3 |
|
$mailer = $container->get(Mailer::class); |
31
|
|
|
|
32
|
|
|
/** @var UserRepository $repository */ |
33
|
3 |
|
$repository = _em()->getRepository(User::class); |
34
|
|
|
|
35
|
|
|
/** @var User $user */ |
36
|
3 |
|
$user = $repository->getByLogin($args['login']); |
37
|
3 |
|
$relationship = RelationshipType::HOUSEHOLDER; |
38
|
|
|
|
39
|
3 |
|
if ($user) { |
40
|
2 |
|
$email = $user->getEmail(); |
41
|
|
|
|
42
|
|
|
// Fallback to householder if any |
43
|
2 |
|
if (!$email && $user->getOwner()) { |
44
|
1 |
|
$repository->getAclFilter()->setEnabled(false); |
45
|
1 |
|
$email = $user->getOwner()->getEmail(); |
46
|
1 |
|
$repository->getAclFilter()->setEnabled(true); |
47
|
|
|
|
48
|
1 |
|
$relationship = $user->getFamilyRelationship(); |
49
|
|
|
} |
50
|
|
|
|
51
|
2 |
|
if ($email) { |
52
|
2 |
|
$message = $mailer->queueResetPassword($user, $email); |
53
|
2 |
|
$mailer->sendMessageAsync($message); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Here we lie to client, and always say we are successful, to avoid data leak |
58
|
3 |
|
return $relationship; |
59
|
1 |
|
}, |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.