From abacd62de9433735f60460d909483d073c67c353 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Sat, 30 Dec 2023 17:29:11 +0100 Subject: [PATCH] different message if you are in an MFA-verified session --- appinfo/routes.php | 1 + js/plugin.js | 26 ++++++++++++++++++++++---- lib/Controller/MfazonesController.php | 12 ++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 38cf691..d1e821f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -6,6 +6,7 @@ return [ 'routes' => [ ['name' => 'mfazones#get', 'url' => '/get', 'verb' => 'GET'], + ['name' => 'mfazones#getMfaStatus', 'url' => '/getMfaStatus', 'verb' => 'GET'], ['name' => 'mfazones#getList', 'url' => '/getList', 'verb' => 'GET'], ['name' => 'mfazones#access', 'url' => '/access', 'verb' => 'GET'], ['name' => 'mfazones#set', 'url' => '/set', 'verb' => 'POST'], diff --git a/js/plugin.js b/js/plugin.js index 8d4a708..68760d0 100644 --- a/js/plugin.js +++ b/js/plugin.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later var mfazoneFileListPlugin = { attach: function(fileList) { - console.log('FILELIST>>>>>>', fileList); + // console.log('FILELIST>>>>>>', fileList); // if (fileList.id === 'trashbin' || fileList.id === 'files.public') { // return; // } @@ -18,9 +18,27 @@ var mfazoneFileListPlugin = { permissions: OC.PERMISSION_NONE, iconClass: 'icon-category-security', actionHandler: function(fileName, context) { - if (confirm('You must enable two factor authentication to use MFAZone app. Do you want to enable 2FA?')) { - window.location.href = OC.generateUrl('/settings/user/security'); - } + const statusUrl = OC.generateUrl('/apps/mfazones/getMfaStatus'); + $.ajax({ + type: 'GET', + url: statusUrl, + dataType: 'json', + async: true, + success: function (response) { + if (response.error){ + console.log(response.error); + return; + } + if (response.mfa_passed !== true) { + const choice = confirm('This folder requires Multi Factor Authentication. Do you want to enable it for your account?') + if (choice) { + window.location.href = OC.generateUrl('/settings/user/security'); + } + } else { + alert('You have already enabled Multi Factor Authentication for your account.'); + } + } + }); }, // fileName: 'asdf', }); diff --git a/lib/Controller/MfazonesController.php b/lib/Controller/MfazonesController.php index 60b9ab7..33064a2 100755 --- a/lib/Controller/MfazonesController.php +++ b/lib/Controller/MfazonesController.php @@ -108,6 +108,18 @@ public function hasAccess($source) } } + /** + * @NoAdminRequired + */ + public function getMfaStatus() + { + return new JSONResponse( + array( + 'mfa_passed' => $this->isMfaVerified() + ) + ); + } + /** * @NoAdminRequired */