|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\CoreBundle\Service; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
14
|
|
|
use libphonenumber\PhoneNumber; |
|
15
|
|
|
use LoginCidadao\CoreBundle\Entity\AccountRecoveryData; |
|
16
|
|
|
use LoginCidadao\CoreBundle\Entity\AccountRecoveryDataRepository; |
|
17
|
|
|
use LoginCidadao\CoreBundle\Model\PersonInterface; |
|
18
|
|
|
|
|
19
|
|
|
class AccountRecoveryService |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var EntityManagerInterface */ |
|
22
|
|
|
private $em; |
|
23
|
|
|
|
|
24
|
|
|
/** @var AccountRecoveryDataRepository */ |
|
25
|
|
|
private $repository; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* AccountRecoveryService constructor. |
|
29
|
|
|
* @param EntityManagerInterface $em |
|
30
|
|
|
* @param AccountRecoveryDataRepository $repository |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(EntityManagerInterface $em, AccountRecoveryDataRepository $repository) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->em = $em; |
|
35
|
|
|
$this->repository = $repository; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getAccountRecoveryData(PersonInterface $person, bool $createIfNotFound = true): ?AccountRecoveryData |
|
39
|
|
|
{ |
|
40
|
|
|
/** @var AccountRecoveryData $data */ |
|
41
|
|
|
$data = $this->repository->findByPerson($person); |
|
42
|
|
|
if (null === $data && $createIfNotFound) { |
|
43
|
|
|
$data = (new AccountRecoveryData()) |
|
44
|
|
|
->setPerson($person); |
|
45
|
|
|
$this->em->persist($data); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $data; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setRecoveryEmail(PersonInterface $person, string $email): AccountRecoveryData |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->getAccountRecoveryData($person) |
|
54
|
|
|
->setEmail($email); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function setRecoveryPhone(PersonInterface $person, PhoneNumber $phoneNumber): AccountRecoveryData |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getAccountRecoveryData($person) |
|
60
|
|
|
->setMobile($phoneNumber); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|