Skip to content

Commit

Permalink
moved account recovery features to it's bundle #797
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermednt committed Aug 7, 2018
1 parent 8135396 commit e64f527
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 37 deletions.
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function registerBundles()
new LoginCidadao\RemoteClaimsBundle\LoginCidadaoRemoteClaimsBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new Snc\RedisBundle\SncRedisBundle(),
new LoginCidadao\AccountRecoveryBundle\LoginCidadaoAccountRecoveryBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
5 changes: 5 additions & 0 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Account Recovery
lc_account_recovery:
resource: "@LoginCidadaoAccountRecoveryBundle/Resources/config/routing.yml"
prefix: /

# Remote Claims
lc_remote_claims_remote_claim:
type: rest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\AccountRecoveryBundle\Controller;

use LoginCidadao\AccountRecoveryBundle\Form\AccountRecoveryDataType;
use LoginCidadao\CoreBundle\Model\PersonInterface;
use LoginCidadao\AccountRecoveryBundle\Service\AccountRecoveryService;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class AccountRecoveryDataController extends Controller
{
/**
* @Route("/account-recovery-data")
* @Template()
*/
public function editAction(Request $request)
{
/** @var PersonInterface $person */
$person = $this->getUser();

/** @var AccountRecoveryService $accountRecoveryService */
$accountRecoveryService = $this->get('lc.account_recovery');

$recoveryData = $accountRecoveryService->getAccountRecoveryData($person);
$form = $this->createForm(AccountRecoveryDataType::class, $recoveryData);
$form->handleRequest($request);
if ($form->isValid()) {
$this->getDoctrine()->getManager()->flush();
}

return [
'form' => $form->createView(),
];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace LoginCidadao\AccountRecoveryBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('login_cidadao_account_recovery');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace LoginCidadao\AccountRecoveryBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class LoginCidadaoAccountRecoveryExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace LoginCidadao\CoreBundle\Entity;
namespace LoginCidadao\AccountRecoveryBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumber;
Expand All @@ -21,7 +21,8 @@
* AccountRecoveryData
*
* @ORM\Table(name="account_recovery_data")
* @ORM\Entity(repositoryClass="LoginCidadao\CoreBundle\Entity\AccountRecoveryDataRepository")
* @ORM\Entity(repositoryClass="LoginCidadao\AccountRecoveryBundle\Entity\AccountRecoveryDataRepository")
* @ORM\HasLifecycleCallbacks
*/
class AccountRecoveryData
{
Expand All @@ -37,7 +38,7 @@ class AccountRecoveryData
/**
* @var PersonInterface
*
* @ORM\ManyToOne(targetEntity="Person")
* @ORM\ManyToOne(targetEntity="LoginCidadao\CoreBundle\Entity\Person")
* @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false)
*/
private $person;
Expand All @@ -48,6 +49,7 @@ class AccountRecoveryData
* @ORM\Column(name="email", type="string", length=255, nullable=true)
* @LCAssert\Email(strict=true)
* @Assert\NotBlank(message="person.validation.email.not_blank")
* @Assert\Expression("value != this.getPerson().getEmail()")
*/
private $email;

Expand All @@ -67,6 +69,7 @@ class AccountRecoveryData
* type="mobile",
* groups={"Registration", "LoginCidadaoRegistration", "Dynamic", "Profile", "LoginCidadaoProfile"}
* )
* @Assert\Expression("value != this.getPerson().getMobile()")
*/
private $mobile;

Expand Down Expand Up @@ -125,7 +128,7 @@ public function getPerson(): PersonInterface
*
* @return AccountRecoveryData
*/
public function setEmail(string $email): AccountRecoveryData
public function setEmail(string $email = null): AccountRecoveryData
{
$this->email = $email;

Expand All @@ -137,7 +140,7 @@ public function setEmail(string $email): AccountRecoveryData
*
* @return string
*/
public function getEmail(): string
public function getEmail(): ?string
{
return $this->email;
}
Expand All @@ -149,7 +152,7 @@ public function getEmail(): string
*
* @return AccountRecoveryData
*/
public function setMobile(PhoneNumber $mobile): AccountRecoveryData
public function setMobile(PhoneNumber $mobile = null): AccountRecoveryData
{
$this->mobile = $mobile;

Expand All @@ -161,56 +164,53 @@ public function setMobile(PhoneNumber $mobile): AccountRecoveryData
*
* @return PhoneNumber
*/
public function getMobile(): PhoneNumber
public function getMobile(): ?PhoneNumber
{
return $this->mobile;
}

/**
* Set createdAt
*
* @param \DateTime $createdAt
* Get createdAt
*
* @return AccountRecoveryData
* @return \DateTime
*/
public function setCreatedAt($createdAt)
public function getCreatedAt()
{
$this->createdAt = $createdAt;

return $this;
return $this->createdAt;
}

/**
* Get createdAt
* Get updatedAt
*
* @return \DateTime
*/
public function getCreatedAt()
public function getUpdatedAt()
{
return $this->createdAt;
return $this->updatedAt;
}

/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return AccountRecoveryData
* @ORM\PrePersist
*/
public function setUpdatedAt($updatedAt)
public function setCreatedAt(): AccountRecoveryData
{
$this->updatedAt = $updatedAt;
if (!$this->getCreatedAt() instanceof \DateTime) {
$this->createdAt = new \DateTime();
}
if (!$this->updatedAt instanceof \DateTime) {
$this->updatedAt = new \DateTime();
}

return $this;
}

/**
* Get updatedAt
*
* @return \DateTime
* @ORM\PreUpdate
*/
public function getUpdatedAt()
public function setUpdatedAt(): AccountRecoveryData
{
return $this->updatedAt;
$this->updatedAt = new \DateTime('now');

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* file that was distributed with this source code.
*/

namespace LoginCidadao\CoreBundle\Entity;
namespace LoginCidadao\AccountRecoveryBundle\Entity;

use Doctrine\ORM\EntityRepository;
use LoginCidadao\CoreBundle\Model\PersonInterface;

/**
Expand All @@ -18,7 +19,7 @@
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class AccountRecoveryDataRepository extends \Doctrine\ORM\EntityRepository
class AccountRecoveryDataRepository extends EntityRepository
{
public function findByPerson(PersonInterface $person): ?AccountRecoveryData
{
Expand Down
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\AccountRecoveryBundle\Form;

use libphonenumber\PhoneNumberFormat;
use LoginCidadao\AccountRecoveryBundle\Entity\AccountRecoveryData;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AccountRecoveryDataType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class)
->add('mobile', PhoneNumberType::class,
[
'required' => false,
'label' => 'person.form.mobile.label',
'attr' => [
'class' => 'form-control intl-tel',
'placeholder' => 'person.form.mobile.placeholder',
],
'label_attr' => ['class' => 'intl-tel-label'],
'format' => PhoneNumberFormat::E164,
]);
}

/**
* @inheritDoc
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => AccountRecoveryData::class,
]);
}


/**
* @return string
*/
public function getName()
{
return 'accrecoverydata';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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\AccountRecoveryBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class LoginCidadaoAccountRecoveryBundle extends Bundle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lc_account_recovery:
resource: "@LoginCidadaoAccountRecoveryBundle/Controller/"
type: annotation
prefix: /
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:

services:
lc.account_recovery.repository:
class: Doctrine\ORM\EntityRepository
factory: ["@doctrine.orm.entity_manager", getRepository]
arguments:
- LoginCidadao\AccountRecoveryBundle\Entity\AccountRecoveryData

lc.account_recovery:
class: LoginCidadao\AccountRecoveryBundle\Service\AccountRecoveryService
arguments:
- "@doctrine.orm.entity_manager"
- "@lc.account_recovery.repository"
Loading

0 comments on commit e64f527

Please sign in to comment.