-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing account recovery data #797
- Loading branch information
1 parent
777f3fd
commit 8135396
Showing
4 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 216 additions & 0 deletions
216
src/LoginCidadao/CoreBundle/Entity/AccountRecoveryData.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
<?php | ||
/** | ||
* This file is part of the login-cidadao project or it's bundles. | ||
* | ||
* (c) Guilherme Donato <guilhermednt on github> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LoginCidadao\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use libphonenumber\PhoneNumber; | ||
use LoginCidadao\CoreBundle\Model\PersonInterface; | ||
use LoginCidadao\ValidationBundle\Validator\Constraints as LCAssert; | ||
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* AccountRecoveryData | ||
* | ||
* @ORM\Table(name="account_recovery_data") | ||
* @ORM\Entity(repositoryClass="LoginCidadao\CoreBundle\Entity\AccountRecoveryDataRepository") | ||
*/ | ||
class AccountRecoveryData | ||
{ | ||
/** | ||
* @var integer | ||
* | ||
* @ORM\Column(name="id", type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var PersonInterface | ||
* | ||
* @ORM\ManyToOne(targetEntity="Person") | ||
* @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false) | ||
*/ | ||
private $person; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @ORM\Column(name="email", type="string", length=255, nullable=true) | ||
* @LCAssert\Email(strict=true) | ||
* @Assert\NotBlank(message="person.validation.email.not_blank") | ||
*/ | ||
private $email; | ||
|
||
/** | ||
* @var PhoneNumber | ||
* | ||
* @ORM\Column(name="mobile", type="phone_number", nullable=true) | ||
* @LCAssert\E164PhoneNumber( | ||
* maxMessage="person.validation.mobile.length.max", | ||
* groups={"Registration", "LoginCidadaoRegistration", "Dynamic", "Profile", "LoginCidadaoProfile"} | ||
* ) | ||
* @LCAssert\MobilePhoneNumber( | ||
* missing9thDigit="person.validation.mobile.9thDigit", | ||
* groups={"Registration", "LoginCidadaoRegistration", "Dynamic", "Profile", "LoginCidadaoProfile"} | ||
* ) | ||
* @AssertPhoneNumber( | ||
* type="mobile", | ||
* groups={"Registration", "LoginCidadaoRegistration", "Dynamic", "Profile", "LoginCidadaoProfile"} | ||
* ) | ||
*/ | ||
private $mobile; | ||
|
||
/** | ||
* @var \DateTime | ||
* | ||
* @ORM\Column(name="created_at", type="datetime") | ||
*/ | ||
private $createdAt; | ||
|
||
/** | ||
* @var \DateTime | ||
* | ||
* @ORM\Column(name="updated_at", type="datetime") | ||
*/ | ||
private $updatedAt; | ||
|
||
/** | ||
* Get id | ||
* | ||
* @return integer | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set person | ||
* | ||
* @param PersonInterface $person | ||
* | ||
* @return AccountRecoveryData | ||
*/ | ||
public function setPerson(PersonInterface $person): AccountRecoveryData | ||
{ | ||
$this->person = $person; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get person | ||
* | ||
* @return PersonInterface | ||
*/ | ||
public function getPerson(): PersonInterface | ||
{ | ||
return $this->person; | ||
} | ||
|
||
/** | ||
* Set email | ||
* | ||
* @param string $email | ||
* | ||
* @return AccountRecoveryData | ||
*/ | ||
public function setEmail(string $email): AccountRecoveryData | ||
{ | ||
$this->email = $email; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get email | ||
* | ||
* @return string | ||
*/ | ||
public function getEmail(): string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* Set mobile | ||
* | ||
* @param PhoneNumber $mobile | ||
* | ||
* @return AccountRecoveryData | ||
*/ | ||
public function setMobile(PhoneNumber $mobile): AccountRecoveryData | ||
{ | ||
$this->mobile = $mobile; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get mobile | ||
* | ||
* @return PhoneNumber | ||
*/ | ||
public function getMobile(): PhoneNumber | ||
{ | ||
return $this->mobile; | ||
} | ||
|
||
/** | ||
* Set createdAt | ||
* | ||
* @param \DateTime $createdAt | ||
* | ||
* @return AccountRecoveryData | ||
*/ | ||
public function setCreatedAt($createdAt) | ||
{ | ||
$this->createdAt = $createdAt; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get createdAt | ||
* | ||
* @return \DateTime | ||
*/ | ||
public function getCreatedAt() | ||
{ | ||
return $this->createdAt; | ||
} | ||
|
||
/** | ||
* Set updatedAt | ||
* | ||
* @param \DateTime $updatedAt | ||
* | ||
* @return AccountRecoveryData | ||
*/ | ||
public function setUpdatedAt($updatedAt) | ||
{ | ||
$this->updatedAt = $updatedAt; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get updatedAt | ||
* | ||
* @return \DateTime | ||
*/ | ||
public function getUpdatedAt() | ||
{ | ||
return $this->updatedAt; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/LoginCidadao/CoreBundle/Entity/AccountRecoveryDataRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* This file is part of the login-cidadao project or it's bundles. | ||
* | ||
* (c) Guilherme Donato <guilhermednt on github> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LoginCidadao\CoreBundle\Entity; | ||
|
||
use LoginCidadao\CoreBundle\Model\PersonInterface; | ||
|
||
/** | ||
* AccountRecoveryDataRepository | ||
* | ||
* This class was generated by the Doctrine ORM. Add your own custom | ||
* repository methods below. | ||
*/ | ||
class AccountRecoveryDataRepository extends \Doctrine\ORM\EntityRepository | ||
{ | ||
public function findByPerson(PersonInterface $person): ?AccountRecoveryData | ||
{ | ||
/** @var AccountRecoveryData|null $data */ | ||
$data = $this->findOneBy(['person' => $person]); | ||
|
||
return $data; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/LoginCidadao/CoreBundle/Service/AccountRecoveryService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* This file is part of the login-cidadao project or it's bundles. | ||
* | ||
* (c) Guilherme Donato <guilhermednt on github> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LoginCidadao\CoreBundle\Service; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use libphonenumber\PhoneNumber; | ||
use LoginCidadao\CoreBundle\Entity\AccountRecoveryData; | ||
use LoginCidadao\CoreBundle\Entity\AccountRecoveryDataRepository; | ||
use LoginCidadao\CoreBundle\Model\PersonInterface; | ||
|
||
class AccountRecoveryService | ||
{ | ||
/** @var EntityManagerInterface */ | ||
private $em; | ||
|
||
/** @var AccountRecoveryDataRepository */ | ||
private $repository; | ||
|
||
/** | ||
* AccountRecoveryService constructor. | ||
* @param EntityManagerInterface $em | ||
* @param AccountRecoveryDataRepository $repository | ||
*/ | ||
public function __construct(EntityManagerInterface $em, AccountRecoveryDataRepository $repository) | ||
{ | ||
$this->em = $em; | ||
$this->repository = $repository; | ||
} | ||
|
||
public function getAccountRecoveryData(PersonInterface $person, bool $createIfNotFound = true): ?AccountRecoveryData | ||
{ | ||
/** @var AccountRecoveryData $data */ | ||
$data = $this->repository->findByPerson($person); | ||
if (null === $data && $createIfNotFound) { | ||
$data = (new AccountRecoveryData()) | ||
->setPerson($person); | ||
$this->em->persist($data); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function setRecoveryEmail(PersonInterface $person, string $email): AccountRecoveryData | ||
{ | ||
return $this->getAccountRecoveryData($person) | ||
->setEmail($email); | ||
} | ||
|
||
public function setRecoveryPhone(PersonInterface $person, PhoneNumber $phoneNumber): AccountRecoveryData | ||
{ | ||
return $this->getAccountRecoveryData($person) | ||
->setMobile($phoneNumber); | ||
} | ||
} |