From 7812675babb5fcf9a971981302d7cd9de4f13502 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Fri, 23 Jul 2021 20:39:40 +0200 Subject: [PATCH] fix: delete indexedDB data on logout Signed-off-by: Gary Kim --- lib/AppInfo/Application.php | 20 +++++++++++++++++++- src/logout.js | 26 ++++++++++++++++++++++++++ webpack.config.js | 7 ++++--- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/logout.js diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 5fd7f6f5..88b4e054 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -25,9 +25,16 @@ namespace OCA\RiotChat\AppInfo; +use OCA\RiotChat\Listener\UserLogoutScriptListener; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\IRequest; +use OCP\User\Events\BeforeUserLoggedOutEvent; +use OCP\Util; -class Application extends App { +class Application extends App implements IBootstrap { public const APP_ID = 'riotchat'; public const AvailableSettings = [ @@ -54,4 +61,15 @@ public static function AvailableLabs() { // TODO: Remove the labs feature fully return []; } + + public function boot(IBootContext $context): void { + $request = $this->getContainer()->get(IRequest::class); + // The user is redirected to '/login?clear=1' + if ($request->getPathInfo() === '/login') { + Util::addScript(self::APP_ID, 'logout'); + } + } + + public function register(IRegistrationContext $context): void { + } } diff --git a/src/logout.js b/src/logout.js new file mode 100644 index 00000000..292876b6 --- /dev/null +++ b/src/logout.js @@ -0,0 +1,26 @@ +/* + * @copyright Copyright (c) 2021 Gary Kim + * + * @author Gary Kim + * + * 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 . + */ + +const url = new URL(window.location); +if (url.searchParams.get('clear') === "1") { + window.indexedDB.deleteDatabase('matrix-react-sdk'); + window.indexedDB.deleteDatabase('matrix-js-sdk:riot-web-sync'); + window.indexedDB.deleteDatabase('matrix-js-sdk:crypto'); +} + diff --git a/webpack.config.js b/webpack.config.js index 7c4fb7d3..a3c4e305 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,7 +6,8 @@ const webpack = require('webpack'); module.exports = { entry: { adminSettings: path.join(__dirname, 'src', 'adminSettings.js'), - main: path.join(__dirname, 'src', 'main.js'), + main: path.join(__dirname, 'src', 'main.js'), + logout: path.join(__dirname, 'src', 'logout.js'), }, output: { path: path.join(__dirname, 'js'), @@ -37,10 +38,10 @@ module.exports = { }, plugins: [ new VueLoaderPlugin(), - new webpack.DefinePlugin({ + new webpack.DefinePlugin({ RIOT_WEB_HASH: JSON.stringify(execSync('git rev-parse HEAD', { cwd: path.resolve(__dirname, './3rdparty/riot-web') }).toString()), RIOT_WEB_VERSION: JSON.stringify(execSync('git describe --exact-match HEAD', { cwd: path.resolve(__dirname, './3rdparty/riot-web') }).toString()), - }), + }), ], resolve: { extensions: ['.js', '.vue'],