2019-01-29 15:23:59 -05:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2019-01-29 15:23:59 -05:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2019-01-29 15:23:59 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-01-29 15:23:59 -05:00
|
|
|
*/
|
|
|
|
|
namespace OC\AppFramework\Middleware;
|
|
|
|
|
|
2023-08-14 11:47:10 -04:00
|
|
|
use OC\Core\Controller\LoginController;
|
|
|
|
|
use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
|
2020-07-13 16:29:14 -04:00
|
|
|
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
2019-01-29 15:23:59 -05:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2019-02-04 02:54:56 -05:00
|
|
|
use OCP\AppFramework\Http\StandaloneTemplateResponse;
|
2019-01-29 15:23:59 -05:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
use OCP\AppFramework\Middleware;
|
2020-07-13 16:29:14 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2019-01-29 15:23:59 -05:00
|
|
|
use OCP\IUserSession;
|
|
|
|
|
|
|
|
|
|
class AdditionalScriptsMiddleware extends Middleware {
|
2023-07-25 05:48:21 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IUserSession $userSession,
|
|
|
|
|
private IEventDispatcher $dispatcher,
|
|
|
|
|
) {
|
2019-01-29 15:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function afterController($controller, $methodName, Response $response): Response {
|
|
|
|
|
if ($response instanceof TemplateResponse) {
|
2023-08-14 11:47:10 -04:00
|
|
|
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));
|
|
|
|
|
}
|
2019-01-29 15:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
}
|