]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #1904 from wallabag/feature-public-mode
authorJeremy Benoist <j0k3r@users.noreply.github.com>
Thu, 25 Aug 2016 07:30:51 +0000 (09:30 +0200)
committerGitHub <noreply@github.com>
Thu, 25 Aug 2016 07:30:51 +0000 (09:30 +0200)
Share entry with a public URL

app/config/config.yml
app/config/parameters.yml.dist
src/Wallabag/UserBundle/Controller/RegistrationController.php [new file with mode: 0644]
src/Wallabag/UserBundle/Controller/SecurityController.php [new file with mode: 0644]
src/Wallabag/UserBundle/DependencyInjection/Configuration.php
src/Wallabag/UserBundle/DependencyInjection/WallabagUserExtension.php
src/Wallabag/UserBundle/Resources/views/Security/login.html.twig
tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php

index 807543930045daf6b6640963c76366dbe9fa4986..30fd60636376415c91c0da22cfa638090cf2ac8e 100644 (file)
@@ -50,6 +50,9 @@ wallabag_core:
     rss_limit: 50
     reading_speed: 1
 
+wallabag_user:
+    registration_enabled: "%fosuser_registration%"
+
 wallabag_import:
     allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain']
     resource_dir: "%kernel.root_dir%/../web/uploads/import"
index d45839f4dacedf3386d332ef3a515d4497b740e3..d092e13932586cba0901c6ce33bb4e832c4fe268 100644 (file)
@@ -34,6 +34,7 @@ parameters:
     twofactor_sender: no-reply@wallabag.org
 
     # fosuser stuff
+    fosuser_registration: true
     fosuser_confirmation: true
 
     from_email: no-reply@wallabag.org
diff --git a/src/Wallabag/UserBundle/Controller/RegistrationController.php b/src/Wallabag/UserBundle/Controller/RegistrationController.php
new file mode 100644 (file)
index 0000000..f81f3a7
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace Wallabag\UserBundle\Controller;
+
+use FOS\UserBundle\Controller\RegistrationController as FOSRegistrationController;
+use Symfony\Component\HttpFoundation\Request;
+
+class RegistrationController extends FOSRegistrationController
+{
+    public function registerAction(Request $request)
+    {
+        if ($this->container->getParameter('wallabag_user.registration_enabled')) {
+            return parent::registerAction($request);
+        }
+
+        return $this->redirectToRoute('fos_user_security_login', [], 301);
+    }
+}
diff --git a/src/Wallabag/UserBundle/Controller/SecurityController.php b/src/Wallabag/UserBundle/Controller/SecurityController.php
new file mode 100644 (file)
index 0000000..83fa0b2
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+namespace Wallabag\UserBundle\Controller;
+
+use FOS\UserBundle\Controller\SecurityController as FOSSecurityController;
+
+/**
+ * Extends login form in order to pass the registration_enabled parameter.
+ */
+class SecurityController extends FOSSecurityController
+{
+    protected function renderLogin(array $data)
+    {
+        return $this->render('FOSUserBundle:Security:login.html.twig',
+            array_merge(
+                $data,
+                ['registration_enabled' => $this->container->getParameter('wallabag_user.registration_enabled')]
+            )
+        );
+    }
+}
index 4223f8dba5e6547597b5356fa1a2e92e050a600c..971ce1a0f9a2358b663fecc04f3370e35913cf95 100644 (file)
@@ -12,6 +12,14 @@ class Configuration implements ConfigurationInterface
         $treeBuilder = new TreeBuilder();
         $rootNode = $treeBuilder->root('wallabag_user');
 
+        $rootNode
+            ->children()
+                ->booleanNode('registration_enabled')
+                    ->defaultValue(true)
+                ->end()
+            ->end()
+        ;
+
         return $treeBuilder;
     }
 }
index c12a893782e34a6ce416c77f631223edb8c0a510..99040f6946bbca1743c7a0e850185659935f9171 100644 (file)
@@ -16,6 +16,7 @@ class WallabagUserExtension extends Extension
 
         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
         $loader->load('services.yml');
+        $container->setParameter('wallabag_user.registration_enabled', $config['registration_enabled']);
     }
 
     public function getAlias()
index 8474b497b069a9964e807c4d6c9a378539a861f5..13a903ab67ca2407514e3f62cc5f6f469024d440 100644 (file)
@@ -33,7 +33,9 @@
     </div>
     <div class="card-action center">
         <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
-        <a href="{{ path('fos_user_registration_register') }}" class="waves-effect waves-light grey btn">{{ 'security.login.register'|trans }}</a>
+        {% if registration_enabled %}
+            <a href="{{ path('fos_user_registration_register') }}" class="waves-effect waves-light grey btn">{{ 'security.login.register'|trans }}</a>
+        {% endif %}
         <button class="btn waves-effect waves-light" type="submit" name="send">
             {{ 'security.login.submit'|trans }}
             <i class="material-icons right">send</i>
index 03355f5abde2d02820ea5ce842c8938dccbe8dda..08f4676ed010d2b3db60410c6bbc4fe4a057dff4 100644 (file)
@@ -69,4 +69,19 @@ class SecurityControllerTest extends WallabagCoreTestCase
         $this->assertTrue($user->isTrustedComputer('ABCDEF'));
         $this->assertFalse($user->isTrustedComputer('FEDCBA'));
     }
+
+    public function testEnabledRegistration()
+    {
+        $client = $this->getClient();
+
+        if (!$client->getContainer()->getParameter('fosuser_registration')) {
+            $this->markTestSkipped('fosuser_registration is not enabled.');
+
+            return;
+        }
+
+        $client->followRedirects();
+        $crawler = $client->request('GET', '/register');
+        $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]);
+    }
 }