Skip to content

Commit

Permalink
implementing CPF verification #804
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermednt committed Aug 16, 2018
1 parent de6706f commit 62fcb8a
Show file tree
Hide file tree
Showing 25 changed files with 944 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function registerBundles()
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
new Vich\UploaderBundle\VichUploaderBundle(),

new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\DiExtraBundle\JMSDiExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
Expand Down Expand Up @@ -76,6 +76,7 @@ public function registerBundles()
new Circle\RestClientBundle\CircleRestClientBundle(),
new PROCERGS\SmsServiceBundle\PROCERGSSmsServiceBundle(),
new PROCERGS\LoginCidadao\PhoneVerificationBundle\PROCERGSPhoneVerificationBundle(),
new PROCERGS\LoginCidadao\CpfVerificationBundle\PROCERGSLoginCidadaoCpfVerificationBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
4 changes: 4 additions & 0 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
procergs_login_cidadao_cpf_verification:
resource: "@PROCERGSLoginCidadaoCpfVerificationBundle/Resources/config/routing.yml"
prefix: /

procergs_login_cidadao_accounting:
resource: "@PROCERGSLoginCidadaoAccountingBundle/Resources/config/routing.yml"
prefix: /
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace PROCERGS\LoginCidadao\CpfVerificationBundle\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('procergs_login_cidadao_cpf_verification');

// 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 PROCERGS\LoginCidadao\CpfVerificationBundle\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 PROCERGSLoginCidadaoCpfVerificationExtension 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
@@ -0,0 +1,35 @@
<?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 PROCERGS\LoginCidadao\CpfVerificationBundle\Exception;

use Throwable;

class CpfNotSubscribedToNfgException extends \RuntimeException
{
public const ERROR_CODE = 'cpf_not_subscribed_to_nfg';

/** @var string */
private $cpf;

public function __construct(string $cpf, string $message = "", int $code = 0, Throwable $previous = null)
{
$this->cpf = $cpf;
parent::__construct($message, $code, $previous);
}

/**
* @return string
*/
public function getCpf(): string
{
return $this->cpf;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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 PROCERGS\LoginCidadao\CpfVerificationBundle\Exception;

use PROCERGS\LoginCidadao\CpfVerificationBundle\Model\ChallengeInterface;
use Throwable;

class WrongAnswerException extends \RuntimeException
{
/** @var ChallengeInterface */
private $challenge;

/**
* @inheritDoc
*/
public function __construct(
ChallengeInterface $challenge,
string $message = "",
int $code = 0,
Throwable $previous = null
) {
$this->challenge = $challenge;
parent::__construct($message, $code, $previous);
}

/**
* @return ChallengeInterface
*/
public function getChallenge(): ChallengeInterface
{
return $this->challenge;
}
}
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 PROCERGS\LoginCidadao\CpfVerificationBundle\Model;

abstract class AbstractChallenge implements ChallengeInterface
{
/** @var string */
private $cpf;

/** @var int */
private $attemptsLeft;

/**
* Challenge constructor.
* @param string $cpf
* @param int $attemptsLeft
*/
public function __construct(int $attemptsLeft, string $cpf)
{
$this->cpf = $cpf;
$this->attemptsLeft = $attemptsLeft;
}

/**
* @return string
*/
public function getCpf(): string
{
return $this->cpf;
}

/**
* @return int
*/
public function getAttemptsLeft(): int
{
return $this->attemptsLeft;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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 PROCERGS\LoginCidadao\CpfVerificationBundle\Model;

class ChallengeFactory
{
public static function create(
string $challengeName,
int $attemptsLeft,
string $cpf,
array $choices = null
): ChallengeInterface {
switch ($challengeName) {
case SelectMotherInitialsChallenge::CHALLENGE_NAME:
return new SelectMotherInitialsChallenge($attemptsLeft, $cpf, $choices ?? []);
case TypeBirthdayChallenge::CHALLENGE_NAME:
return new TypeBirthdayChallenge($attemptsLeft, $cpf);
case TypeMotherInitialsChallenge::CHALLENGE_NAME:
return new TypeMotherInitialsChallenge($attemptsLeft, $cpf);
case TypePostalCodeChallenge::CHALLENGE_NAME:
return new TypePostalCodeChallenge($attemptsLeft, $cpf);
case TypeVoterRegistrationChallenge::CHALLENGE_NAME:
return new TypeVoterRegistrationChallenge($attemptsLeft, $cpf);
default:
throw new \InvalidArgumentException("Unsupported challenge '{$challengeName}'");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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 PROCERGS\LoginCidadao\CpfVerificationBundle\Model;

interface ChallengeInterface
{
/**
* @return string
*/
public function getName(): string;

/**
* @return string
*/
public function getCpf(): string;

/**
* @return int
*/
public function getAttemptsLeft(): int;
}
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 PROCERGS\LoginCidadao\CpfVerificationBundle\Model;

class SelectMotherInitialsChallenge extends AbstractChallenge
{
public const CHALLENGE_NAME = 'select_mother_initials';

/** @var string[] */
private $choices;

/**
* SelectMotherInitialsChallenge constructor.
* @param int $attemptsLeft
* @param string $cpf
* @param string[] $choices
*/
public function __construct(int $attemptsLeft, string $cpf, array $choices)
{
$this->choices = $choices;
parent::__construct($attemptsLeft, $cpf);
}

/**
* @inheritDoc
*/
public function getName(): string
{
return self::CHALLENGE_NAME;
}

/**
* @return string[]
*/
public function getChoices(): array
{
return $this->choices;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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 PROCERGS\LoginCidadao\CpfVerificationBundle\Model;

class TypeBirthdayChallenge extends AbstractChallenge
{
public const CHALLENGE_NAME = 'type_birthday';

/**
* @inheritDoc
*/
public function getName(): string
{
return self::CHALLENGE_NAME;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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 PROCERGS\LoginCidadao\CpfVerificationBundle\Model;

class TypeMotherInitialsChallenge extends AbstractChallenge
{
public const CHALLENGE_NAME = 'type_mother_initials';

/**
* @inheritDoc
*/
public function getName(): string
{
return self::CHALLENGE_NAME;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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 PROCERGS\LoginCidadao\CpfVerificationBundle\Model;

class TypePostalCodeChallenge extends AbstractChallenge
{
public const CHALLENGE_NAME = 'type_postal_code';

/**
* @inheritDoc
*/
public function getName(): string
{
return self::CHALLENGE_NAME;
}
}
Loading

0 comments on commit 62fcb8a

Please sign in to comment.