|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Palladium\Service; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Application logic for password reset handling |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Palladium\Mapper as Mapper; |
|
10
|
|
|
use Palladium\Entity as Entity; |
|
11
|
|
|
use Palladium\Exception\IdentityNotFound; |
|
12
|
|
|
use Palladium\Exception\IdentityNotVerified; |
|
13
|
|
|
|
|
14
|
|
|
use Palladium\Contract\CanCreateMapper; |
|
15
|
|
|
use Psr\Log\LoggerInterface; |
|
16
|
|
|
|
|
17
|
|
|
class Recovery |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
protected $mapperFactory; |
|
21
|
|
|
protected $logger; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
1 |
|
public function __construct(CanCreateMapper $mapperFactory, LoggerInterface $logger) |
|
25
|
|
|
{ |
|
26
|
1 |
|
$this->mapperFactory = $mapperFactory; |
|
27
|
1 |
|
$this->logger = $logger; |
|
28
|
1 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public function markForReset(Entity\EmailIdentity $identity) |
|
32
|
|
|
{ |
|
33
|
|
|
if ($identity->getStatus() === Entity\Identity::STATUS_NEW) { |
|
34
|
|
|
$this->logger->warning('account not verified', [ |
|
35
|
|
|
'input' => [ |
|
36
|
|
|
'identifier' => $identifier, |
|
|
|
|
|
|
37
|
|
|
], |
|
38
|
|
|
'account' => [ |
|
39
|
|
|
'user' => $identity->getUserId(), |
|
40
|
|
|
'identity' => $identity->getId(), |
|
41
|
|
|
], |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
throw new IdentityNotVerified; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$identity->generateToken(); |
|
48
|
|
|
$identity->setTokenAction(Entity\Identity::ACTION_RESET); |
|
49
|
|
|
$identity->setTokenEndOfLife(time() + Entity\Identity::TOKEN_LIFESPAN); |
|
50
|
|
|
|
|
51
|
|
|
$mapper = $this->mapperFactory->create(Mapper\EmailIdentity::class); |
|
52
|
|
|
$mapper->store($identity); |
|
53
|
|
|
|
|
54
|
|
|
$this->logger->info('request password reset', [ |
|
55
|
|
|
'input' => [ |
|
56
|
|
|
'identifier' => $identifier, |
|
57
|
|
|
], |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
1 |
|
public function resetIdentityPassword(Entity\EmailIdentity $identity, $password) |
|
64
|
|
|
{ |
|
65
|
1 |
|
$token = $identity->getToken(); |
|
66
|
|
|
|
|
67
|
1 |
|
$identity->setPassword($password); |
|
68
|
1 |
|
$identity->clearToken(); |
|
69
|
|
|
|
|
70
|
1 |
|
$mapper = $this->mapperFactory->create(Mapper\EmailIdentity::class); |
|
71
|
1 |
|
$mapper->store($identity); |
|
72
|
|
|
|
|
73
|
1 |
|
$this->logger->info('password reset successful', [ |
|
74
|
|
|
'input' => [ |
|
75
|
1 |
|
'token' => $token, |
|
76
|
|
|
], |
|
77
|
|
|
]); |
|
78
|
1 |
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.