Commit e7414e79 authored by Mat's avatar Mat

token auth: factorisation, debug, et adapte l'envoi via la commande

parent 34869394
...@@ -4,6 +4,7 @@ namespace PotageBundle\Command; ...@@ -4,6 +4,7 @@ namespace PotageBundle\Command;
use PotageBundle\Entity\Groupe; use PotageBundle\Entity\Groupe;
use PotageBundle\Entity\Lettre; use PotageBundle\Entity\Lettre;
use PotageBundle\Services\LettreToken;
use PotageBundle\Services\Newsletter; use PotageBundle\Services\Newsletter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
...@@ -11,31 +12,35 @@ use Symfony\Component\Console\Output\OutputInterface; ...@@ -11,31 +12,35 @@ use Symfony\Component\Console\Output\OutputInterface;
class SendMailCommand extends ContainerAwareCommand class SendMailCommand extends ContainerAwareCommand
{ {
/**
* {@inheritdoc} private $newsletter;
*/ private $lettreToken;
protected function configure()
{
$this
->setName('potage:mail:send')
->setDescription("Test d'envoi d'une infolettre!");
}
public $newsletter;
/** /**
* SendMailCommand constructor. * SendMailCommand constructor.
* *
* @param Newsletter $newsletter * @param Newsletter $newsletter
* @param LettreToken $lettreToken
*/ */
public function __construct(Newsletter $newsletter) public function __construct(Newsletter $newsletter, LettreToken $lettreToken)
{ {
parent::__construct(); parent::__construct();
$this->newsletter = $newsletter; $this->newsletter = $newsletter;
$this->lettreToken = $lettreToken;
} }
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('potage:mail:send')
->setDescription("Test d'envoi d'une infolettre!");
}
/** /**
* @param InputInterface $input * @param InputInterface $input
* @param OutputInterface $output * @param OutputInterface $output
...@@ -54,7 +59,7 @@ class SendMailCommand extends ContainerAwareCommand ...@@ -54,7 +59,7 @@ class SendMailCommand extends ContainerAwareCommand
->getRepository('PotageBundle:Lettre') ->getRepository('PotageBundle:Lettre')
->findOneForSend(7); ->findOneForSend(7);
$retour = $this->newsletter->sendLettreToGroup($lettre); $retour = $this->newsletter->sendLettreToGroup($lettre, $this->lettreToken);
for ($i = 0; $i < count($retour); $i++) { for ($i = 0; $i < count($retour); $i++) {
$output->writeln($i .' | '. $retour[$i]['to'] .' | '. $retour[$i]['result']); $output->writeln($i .' | '. $retour[$i]['to'] .' | '. $retour[$i]['result']);
......
...@@ -110,10 +110,18 @@ class DefaultController extends MasterController ...@@ -110,10 +110,18 @@ class DefaultController extends MasterController
} }
} }
/**
* pour debug
*/
$tokenEncoded = $request->query->get('token');
$tokenDecoded = $lettreToken->decodePotageAccess($tokenEncoded);
return $this->render('@Potage/Default/today.html.twig', array( return $this->render('@Potage/Default/today.html.twig', array(
'user' => $user, 'user' => $user,
'groupes' => $groupes 'groupes' => $groupes,
'tokenEncoded' => $tokenEncoded,
'tokenDecoded' => $tokenDecoded,
)); ));
} }
......
...@@ -96,10 +96,10 @@ class TokenAuthenticator extends AbstractGuardAuthenticator ...@@ -96,10 +96,10 @@ class TokenAuthenticator extends AbstractGuardAuthenticator
public function getCredentials(Request $request) public function getCredentials(Request $request)
{ {
$tokenEncoded = $request->query->get('token'); $tokenEncoded = $request->query->get('token');
$inToken = $this->lettreToken->decodePotageAccess($tokenEncoded); $tokenDecoded = $this->lettreToken->decodePotageAccess($tokenEncoded);
return array( return array(
'token' => $inToken['user_token'], 'token_key' => $tokenDecoded['token_key'],
); );
} }
...@@ -120,7 +120,7 @@ class TokenAuthenticator extends AbstractGuardAuthenticator ...@@ -120,7 +120,7 @@ class TokenAuthenticator extends AbstractGuardAuthenticator
*/ */
public function getUser($credentials, UserProviderInterface $userProvider) public function getUser($credentials, UserProviderInterface $userProvider)
{ {
$tokenKey = $credentials['token']; $tokenKey = $credentials['token_key'];
if (null === $tokenKey) { if (null === $tokenKey) {
return null; return null;
......
...@@ -82,7 +82,7 @@ class LettreToken ...@@ -82,7 +82,7 @@ class LettreToken
return array( return array(
'user_id' => $data[0], 'user_id' => $data[0],
'user_token' => $data[1], 'token_key' => $data[1],
'lettre_id' => $data[2], 'lettre_id' => $data[2],
'lettre_ref' => $data[3], 'lettre_ref' => $data[3],
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment