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;
use PotageBundle\Entity\Groupe;
use PotageBundle\Entity\Lettre;
use PotageBundle\Services\LettreToken;
use PotageBundle\Services\Newsletter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
......@@ -11,31 +12,35 @@ use Symfony\Component\Console\Output\OutputInterface;
class SendMailCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('potage:mail:send')
->setDescription("Test d'envoi d'une infolettre!");
}
public $newsletter;
private $newsletter;
private $lettreToken;
/**
* SendMailCommand constructor.
*
* @param Newsletter $newsletter
* @param LettreToken $lettreToken
*/
public function __construct(Newsletter $newsletter)
public function __construct(Newsletter $newsletter, LettreToken $lettreToken)
{
parent::__construct();
$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 OutputInterface $output
......@@ -54,7 +59,7 @@ class SendMailCommand extends ContainerAwareCommand
->getRepository('PotageBundle:Lettre')
->findOneForSend(7);
$retour = $this->newsletter->sendLettreToGroup($lettre);
$retour = $this->newsletter->sendLettreToGroup($lettre, $this->lettreToken);
for ($i = 0; $i < count($retour); $i++) {
$output->writeln($i .' | '. $retour[$i]['to'] .' | '. $retour[$i]['result']);
......
......@@ -111,9 +111,17 @@ class DefaultController extends MasterController
}
/**
* pour debug
*/
$tokenEncoded = $request->query->get('token');
$tokenDecoded = $lettreToken->decodePotageAccess($tokenEncoded);
return $this->render('@Potage/Default/today.html.twig', array(
'user' => $user,
'groupes' => $groupes
'groupes' => $groupes,
'tokenEncoded' => $tokenEncoded,
'tokenDecoded' => $tokenDecoded,
));
}
......
......@@ -96,10 +96,10 @@ class TokenAuthenticator extends AbstractGuardAuthenticator
public function getCredentials(Request $request)
{
$tokenEncoded = $request->query->get('token');
$inToken = $this->lettreToken->decodePotageAccess($tokenEncoded);
$tokenDecoded = $this->lettreToken->decodePotageAccess($tokenEncoded);
return array(
'token' => $inToken['user_token'],
'token_key' => $tokenDecoded['token_key'],
);
}
......@@ -120,7 +120,7 @@ class TokenAuthenticator extends AbstractGuardAuthenticator
*/
public function getUser($credentials, UserProviderInterface $userProvider)
{
$tokenKey = $credentials['token'];
$tokenKey = $credentials['token_key'];
if (null === $tokenKey) {
return null;
......
......@@ -82,7 +82,7 @@ class LettreToken
return array(
'user_id' => $data[0],
'user_token' => $data[1],
'token_key' => $data[1],
'lettre_id' => $data[2],
'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