]> source.dussan.org Git - nextcloud-server.git/commitdiff
add separate event for rendering login page template
authorRobin Appelman <robin@icewind.nl>
Mon, 14 Aug 2023 15:47:10 +0000 (17:47 +0200)
committerRobin Appelman <robin@icewind.nl>
Thu, 17 Aug 2023 08:57:56 +0000 (10:57 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/theming/lib/AppInfo/Application.php
core/Application.php
core/Listener/BeforeTemplateRenderedListener.php
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php
lib/private/legacy/OC_Template.php
lib/public/AppFramework/Http/Events/BeforeLoginTemplateRenderedEvent.php [new file with mode: 0644]

index 48bf42252c7d370f70083e63584059aa306b68c8..43b854012f7d3db857f4d7292ec24c1bbd531414 100644 (file)
@@ -31,6 +31,7 @@ use OCP\AppFramework\App;
 use OCP\AppFramework\Bootstrap\IBootContext;
 use OCP\AppFramework\Bootstrap\IBootstrap;
 use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
 use OCP\Config\BeforePreferenceDeletedEvent;
 use OCP\Config\BeforePreferenceSetEvent;
@@ -45,6 +46,7 @@ class Application extends App implements IBootstrap {
        public function register(IRegistrationContext $context): void {
                $context->registerCapability(Capabilities::class);
                $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
+               $context->registerEventListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
                $context->registerEventListener(BeforePreferenceSetEvent::class, BeforePreferenceListener::class);
                $context->registerEventListener(BeforePreferenceDeletedEvent::class, BeforePreferenceListener::class);
        }
index 307d839f07cebceae96e51f2b9a9d11af7aadc37..ca9b6ce2d8c1b8f4578816dec05e679b23b1f2bf 100644 (file)
@@ -47,6 +47,7 @@ use OC\Core\Notification\CoreNotifier;
 use OC\Metadata\FileEventListener;
 use OC\TagManager;
 use OCP\AppFramework\App;
+use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
 use OCP\DB\Events\AddMissingColumnsEvent;
 use OCP\DB\Events\AddMissingIndicesEvent;
@@ -317,6 +318,7 @@ class Application extends App {
                });
 
                $eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
+               $eventDispatcher->addServiceListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
                $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
                $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
                $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
index b3ab7c429e8bcba5b42bf25992d22ce75d3fa563..c453d010a4c5b527f49fb4591c075ac2e6886244 100644 (file)
@@ -38,7 +38,7 @@ class BeforeTemplateRenderedListener implements IEventListener {
        }
 
        public function handle(Event $event): void {
-               if (!($event instanceof BeforeTemplateRenderedEvent)) {
+               if (!($event instanceof BeforeTemplateRenderedEvent || $event instanceof BeforeLoginTemplateRenderedEvent)) {
                        return;
                }
 
@@ -50,7 +50,6 @@ class BeforeTemplateRenderedListener implements IEventListener {
                \OC_Util::addStyle('server', null, true);
 
                if ($event instanceof BeforeTemplateRenderedEvent) {
-
                        // include common nextcloud webpack bundle
                        Util::addScript('core', 'common');
                        Util::addScript('core', 'main');
index 2e5c239b6ed1be8d6351debe87de03bec40280ac..b615d9fe35f313517515d1c56a1d217747a1cb09 100644 (file)
@@ -57,6 +57,7 @@ return array(
     'OCP\\AppFramework\\Http\\DownloadResponse' => $baseDir . '/lib/public/AppFramework/Http/DownloadResponse.php',
     'OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy' => $baseDir . '/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php',
     'OCP\\AppFramework\\Http\\EmptyFeaturePolicy' => $baseDir . '/lib/public/AppFramework/Http/EmptyFeaturePolicy.php',
+    'OCP\\AppFramework\\Http\\Events\\BeforeLoginTemplateRenderedEvent' => $baseDir . '/lib/public/AppFramework/Http/Events/BeforeLoginTemplateRenderedEvent.php',
     'OCP\\AppFramework\\Http\\Events\\BeforeTemplateRenderedEvent' => $baseDir . '/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php',
     'OCP\\AppFramework\\Http\\FeaturePolicy' => $baseDir . '/lib/public/AppFramework/Http/FeaturePolicy.php',
     'OCP\\AppFramework\\Http\\FileDisplayResponse' => $baseDir . '/lib/public/AppFramework/Http/FileDisplayResponse.php',
index 48c6701c7c60535aaf43a63004e6f62d3d6afb3d..0449be199f2fd444795b0ce60b08d64d62ebc3c2 100644 (file)
@@ -90,6 +90,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
         'OCP\\AppFramework\\Http\\DownloadResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/DownloadResponse.php',
         'OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php',
         'OCP\\AppFramework\\Http\\EmptyFeaturePolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/EmptyFeaturePolicy.php',
+        'OCP\\AppFramework\\Http\\Events\\BeforeLoginTemplateRenderedEvent' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Events/BeforeLoginTemplateRenderedEvent.php',
         'OCP\\AppFramework\\Http\\Events\\BeforeTemplateRenderedEvent' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php',
         'OCP\\AppFramework\\Http\\FeaturePolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/FeaturePolicy.php',
         'OCP\\AppFramework\\Http\\FileDisplayResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/FileDisplayResponse.php',
index f3f9b07f2a87a2950f5668498d2b2d35a0eb4dd5..64b1c7d2fcdbcebf883bedb2ea7d1e8a0ba10a6b 100644 (file)
@@ -27,6 +27,8 @@ declare(strict_types=1);
  */
 namespace OC\AppFramework\Middleware;
 
+use OC\Core\Controller\LoginController;
+use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
 use OCP\AppFramework\Http\Response;
 use OCP\AppFramework\Http\StandaloneTemplateResponse;
@@ -44,8 +46,12 @@ class AdditionalScriptsMiddleware extends Middleware {
 
        public function afterController($controller, $methodName, Response $response): Response {
                if ($response instanceof TemplateResponse) {
-                       $isLoggedIn = !($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn();
-                       $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
+                       if ($controller instanceof LoginController) {
+                               $this->dispatcher->dispatchTyped(new BeforeLoginTemplateRenderedEvent($response));
+                       } else {
+                               $isLoggedIn = !($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn();
+                               $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
+                       }
                }
 
                return $response;
index 3d27475590f2e3b4d67c1736e580de3f92dcb85c..974f26fa38122020fe05a8d2d2f3bea3ffd0ba7a 100644 (file)
@@ -39,7 +39,6 @@
  */
 use OC\TemplateLayout;
 use OCP\AppFramework\Http\TemplateResponse;
-use OCP\Util;
 
 require_once __DIR__.'/template/functions.php';
 
diff --git a/lib/public/AppFramework/Http/Events/BeforeLoginTemplateRenderedEvent.php b/lib/public/AppFramework/Http/Events/BeforeLoginTemplateRenderedEvent.php
new file mode 100644 (file)
index 0000000..99c1275
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCP\AppFramework\Http\Events;
+
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\EventDispatcher\Event;
+
+/**
+ * Emitted before the rendering step of the login TemplateResponse.
+ *
+ * @since 28.0.0
+ */
+class BeforeLoginTemplateRenderedEvent extends Event {
+       /**
+        * @since 28.0.0
+        */
+       public function __construct(private TemplateResponse $response) {
+               parent::__construct();
+       }
+
+       /**
+        * @since 28.0.0
+        */
+       public function getResponse(): TemplateResponse {
+               return $this->response;
+       }
+}