aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2020-04-11 14:01:00 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2020-04-12 15:35:00 +0200
commit607e1a1a13d0aaf625ff760aa094f970f2924757 (patch)
tree01101533cf529e7725966052eaea18d8ee233625
parent365b3dd21f7c4f3e7f2b6f1502f284a6190dd918 (diff)
downloadwallabag-607e1a1a13d0aaf625ff760aa094f970f2924757.tar.gz
wallabag-607e1a1a13d0aaf625ff760aa094f970f2924757.tar.zst
wallabag-607e1a1a13d0aaf625ff760aa094f970f2924757.zip
Added authentication during import command for paywalled websites
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php
index f9ffe994..26903e9c 100644
--- a/src/Wallabag/ImportBundle/Command/ImportCommand.php
+++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php
@@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Input\InputOption; 9use Symfony\Component\Console\Input\InputOption;
10use Symfony\Component\Console\Output\OutputInterface; 10use Symfony\Component\Console\Output\OutputInterface;
11use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
11 12
12class ImportCommand extends ContainerAwareCommand 13class ImportCommand extends ContainerAwareCommand
13{ 14{
@@ -38,15 +39,25 @@ class ImportCommand extends ContainerAwareCommand
38 $em->getConnection()->getConfiguration()->setSQLLogger(null); 39 $em->getConnection()->getConfiguration()->setSQLLogger(null);
39 40
40 if ($input->getOption('useUserId')) { 41 if ($input->getOption('useUserId')) {
41 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username')); 42 $entityUser = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username'));
42 } else { 43 } else {
43 $user = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username')); 44 $entityUser = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username'));
44 } 45 }
45 46
46 if (!\is_object($user)) { 47 if (!\is_object($entityUser)) {
47 throw new Exception(sprintf('User "%s" not found', $input->getArgument('username'))); 48 throw new Exception(sprintf('User "%s" not found', $input->getArgument('username')));
48 } 49 }
49 50
51 // Authenticate user for paywalled websites
52 $token = new UsernamePasswordToken(
53 $entityUser,
54 null,
55 'main',
56 $entityUser->getRoles());
57
58 $this->getContainer()->get('security.token_storage')->setToken($token);
59 $user = $this->getContainer()->get('security.token_storage')->getToken()->getUser();
60
50 switch ($input->getOption('importer')) { 61 switch ($input->getOption('importer')) {
51 case 'v2': 62 case 'v2':
52 $import = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); 63 $import = $this->getContainer()->get('wallabag_import.wallabag_v2.import');