Skip to content

Commit

Permalink
implementing account recovery data #797
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermednt committed Aug 6, 2018
1 parent 777f3fd commit 8135396
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ simple_things_entity_audit:
- LoginCidadao\CoreBundle\Entity\PersonAddress
- LoginCidadao\CoreBundle\Entity\SentEmail
- LoginCidadao\CoreBundle\Entity\State
- LoginCidadao\CoreBundle\Entity\AccountRecoveryData

- LoginCidadao\OAuthBundle\Entity\AccessToken
- LoginCidadao\OAuthBundle\Entity\AuthCode
Expand Down
216 changes: 216 additions & 0 deletions src/LoginCidadao/CoreBundle/Entity/AccountRecoveryData.php
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;
}
}
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 src/LoginCidadao/CoreBundle/Service/AccountRecoveryService.php
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);
}
}

0 comments on commit 8135396

Please sign in to comment.