Skip to content

Commit 40cf409

Browse files
committed
add separate event for rendering login page template
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent c4085b0 commit 40cf409

8 files changed

Lines changed: 67 additions & 5 deletions

File tree

apps/theming/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\AppFramework\Bootstrap\IBootContext;
3232
use OCP\AppFramework\Bootstrap\IBootstrap;
3333
use OCP\AppFramework\Bootstrap\IRegistrationContext;
34+
use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
3435
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
3536
use OCP\Config\BeforePreferenceDeletedEvent;
3637
use OCP\Config\BeforePreferenceSetEvent;
@@ -45,6 +46,7 @@ public function __construct() {
4546
public function register(IRegistrationContext $context): void {
4647
$context->registerCapability(Capabilities::class);
4748
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
49+
$context->registerEventListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
4850
$context->registerEventListener(BeforePreferenceSetEvent::class, BeforePreferenceListener::class);
4951
$context->registerEventListener(BeforePreferenceDeletedEvent::class, BeforePreferenceListener::class);
5052
}

core/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use OC\Metadata\FileEventListener;
4848
use OC\TagManager;
4949
use OCP\AppFramework\App;
50+
use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
5051
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
5152
use OCP\DB\Events\AddMissingColumnsEvent;
5253
use OCP\DB\Events\AddMissingIndicesEvent;
@@ -317,6 +318,7 @@ public function __construct() {
317318
});
318319

319320
$eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
321+
$eventDispatcher->addServiceListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
320322
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
321323
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
322324
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);

core/Listener/BeforeTemplateRenderedListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(private IConfig $config) {
3838
}
3939

4040
public function handle(Event $event): void {
41-
if (!($event instanceof BeforeTemplateRenderedEvent)) {
41+
if (!($event instanceof BeforeTemplateRenderedEvent || $event instanceof BeforeLoginTemplateRenderedEvent)) {
4242
return;
4343
}
4444

@@ -50,7 +50,6 @@ public function handle(Event $event): void {
5050
\OC_Util::addStyle('server', null, true);
5151

5252
if ($event instanceof BeforeTemplateRenderedEvent) {
53-
5453
// include common nextcloud webpack bundle
5554
Util::addScript('core', 'common');
5655
Util::addScript('core', 'main');

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
'OCP\\AppFramework\\Http\\DownloadResponse' => $baseDir . '/lib/public/AppFramework/Http/DownloadResponse.php',
5858
'OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy' => $baseDir . '/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php',
5959
'OCP\\AppFramework\\Http\\EmptyFeaturePolicy' => $baseDir . '/lib/public/AppFramework/Http/EmptyFeaturePolicy.php',
60+
'OCP\\AppFramework\\Http\\Events\\BeforeLoginTemplateRenderedEvent' => $baseDir . '/lib/public/AppFramework/Http/Events/BeforeLoginTemplateRenderedEvent.php',
6061
'OCP\\AppFramework\\Http\\Events\\BeforeTemplateRenderedEvent' => $baseDir . '/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php',
6162
'OCP\\AppFramework\\Http\\FeaturePolicy' => $baseDir . '/lib/public/AppFramework/Http/FeaturePolicy.php',
6263
'OCP\\AppFramework\\Http\\FileDisplayResponse' => $baseDir . '/lib/public/AppFramework/Http/FileDisplayResponse.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
9090
'OCP\\AppFramework\\Http\\DownloadResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/DownloadResponse.php',
9191
'OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php',
9292
'OCP\\AppFramework\\Http\\EmptyFeaturePolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/EmptyFeaturePolicy.php',
93+
'OCP\\AppFramework\\Http\\Events\\BeforeLoginTemplateRenderedEvent' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Events/BeforeLoginTemplateRenderedEvent.php',
9394
'OCP\\AppFramework\\Http\\Events\\BeforeTemplateRenderedEvent' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php',
9495
'OCP\\AppFramework\\Http\\FeaturePolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/FeaturePolicy.php',
9596
'OCP\\AppFramework\\Http\\FileDisplayResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/FileDisplayResponse.php',

lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
namespace OC\AppFramework\Middleware;
2929

30+
use OC\Core\Controller\LoginController;
31+
use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
3032
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
3133
use OCP\AppFramework\Http\Response;
3234
use OCP\AppFramework\Http\StandaloneTemplateResponse;
@@ -44,8 +46,12 @@ public function __construct(
4446

4547
public function afterController($controller, $methodName, Response $response): Response {
4648
if ($response instanceof TemplateResponse) {
47-
$isLoggedIn = !($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn();
48-
$this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
49+
if ($controller instanceof LoginController) {
50+
$this->dispatcher->dispatchTyped(new BeforeLoginTemplateRenderedEvent($response));
51+
} else {
52+
$isLoggedIn = !($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn();
53+
$this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
54+
}
4955
}
5056

5157
return $response;

lib/private/legacy/OC_Template.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
*/
4040
use OC\TemplateLayout;
4141
use OCP\AppFramework\Http\TemplateResponse;
42-
use OCP\Util;
4342

4443
require_once __DIR__.'/template/functions.php';
4544

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
7+
*
8+
* @author Julius Härtl <jus@bitgrid.net>
9+
* @author Morris Jobke <hey@morrisjobke.de>
10+
* @author Roeland Jago Douma <roeland@famdouma.nl>
11+
*
12+
* @license GNU AGPL version 3 or any later version
13+
*
14+
* This program is free software: you can redistribute it and/or modify
15+
* it under the terms of the GNU Affero General Public License as
16+
* published by the Free Software Foundation, either version 3 of the
17+
* License, or (at your option) any later version.
18+
*
19+
* This program is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU Affero General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Affero General Public License
25+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
*
27+
*/
28+
namespace OCP\AppFramework\Http\Events;
29+
30+
use OCP\AppFramework\Http\TemplateResponse;
31+
use OCP\EventDispatcher\Event;
32+
33+
/**
34+
* Emitted before the rendering step of the login TemplateResponse.
35+
*
36+
* @since 28.0.0
37+
*/
38+
class BeforeLoginTemplateRenderedEvent extends Event {
39+
/**
40+
* @since 28.0.0
41+
*/
42+
public function __construct(private TemplateResponse $response) {
43+
parent::__construct();
44+
}
45+
46+
/**
47+
* @since 28.0.0
48+
*/
49+
public function getResponse(): TemplateResponse {
50+
return $this->response;
51+
}
52+
}

0 commit comments

Comments
 (0)