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 PasswordResetRequestHandler |
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
|
|
|
* @return int |
43
|
|
|
*/ |
44
|
|
|
public function handle(RequestPasswordReset $command) |
45
|
|
|
{ |
46
|
|
|
$user = $command->getUser(); |
47
|
|
|
$user->generatePasswordResetToken(); |
48
|
|
|
$repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user)); |
49
|
|
|
$repository->save($user); |
50
|
|
|
|
51
|
|
|
$this->sendPasswordResetToken($user); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Sends the password reset token to the user. |
56
|
|
|
* |
57
|
|
|
* @param UserPasswordReset $user |
58
|
|
|
* |
59
|
|
|
* @return int |
60
|
|
|
*/ |
61
|
|
|
private function sendPasswordResetToken(UserPasswordReset $user) |
62
|
|
|
{ |
63
|
|
|
$event = new PasswordResetTokenCreated($user); |
64
|
|
|
$this->dispatcher->dispatch('multi_user.event.password_reset_token_created', $event); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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..