|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkMultiUserBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Event\PasswordResetTokenCreated; |
|
6
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\PasswordReset as UserPasswordReset; |
|
7
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection; |
|
8
|
|
|
use Swift_Mailer; |
|
9
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
10
|
|
|
|
|
11
|
|
|
class RequestPasswordResetHandler |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var UserRepositoryCollection |
|
15
|
|
|
*/ |
|
16
|
|
|
private $userRepositoryCollection; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var EventDispatcher |
|
20
|
|
|
*/ |
|
21
|
|
|
private $dispatcher; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* PasswordResetRequestHandler constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param UserRepositoryCollection $userRepositoryCollection |
|
27
|
|
|
* @param EventDispatcherInterface $dispatcher |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct( |
|
30
|
|
|
UserRepositoryCollection $userRepositoryCollection, |
|
31
|
|
|
EventDispatcherInterface $dispatcher |
|
32
|
|
|
) { |
|
33
|
|
|
$this->userRepositoryCollection = $userRepositoryCollection; |
|
34
|
|
|
$this->dispatcher = $dispatcher; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Creates a password reset token and sends an email to the user. |
|
39
|
|
|
* |
|
40
|
|
|
* @param RequestPasswordReset $command |
|
41
|
|
|
*/ |
|
42
|
|
|
public function handle(RequestPasswordReset $command) |
|
43
|
|
|
{ |
|
44
|
|
|
$user = $command->getUser(); |
|
45
|
|
|
$user->generatePasswordResetToken(); |
|
46
|
|
|
$repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user)); |
|
47
|
|
|
$repository->save($user); |
|
48
|
|
|
|
|
49
|
|
|
$this->sendPasswordResetToken($user); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Sends the password reset token to the user. |
|
54
|
|
|
* |
|
55
|
|
|
* @param UserPasswordReset $user |
|
56
|
|
|
*/ |
|
57
|
|
|
private function sendPasswordResetToken(UserPasswordReset $user) |
|
58
|
|
|
{ |
|
59
|
|
|
$event = new PasswordResetTokenCreated($user); |
|
60
|
|
|
$this->dispatcher->dispatch(PasswordResetTokenCreated::NAME, $event); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..