From e4fa01a6e72471fb843de2cee1082c6d508af82c Mon Sep 17 00:00:00 2001 From: Nathan Kinkade Date: Thu, 14 May 2020 05:42:11 -0600 Subject: [PATCH 1/2] Gets admin and personal settings working again within the context of the NC App Framework. --- rainloop/appinfo/app.php | 2 + rainloop/appinfo/info.xml | 5 ++- rainloop/lib/AppInfo/Application.php | 17 ++++++++ rainloop/lib/Controller/AjaxController.php | 30 ++++++++++----- rainloop/lib/Controller/PageController.php | 4 ++ rainloop/lib/Settings/AdminSettings.php | 45 ++++++++++++++++++++++ rainloop/lib/Settings/PersonalSettings.php | 32 +++++++++++++++ rainloop/templates/admin-local.php | 2 + rainloop/templates/personal.php | 28 ++++---------- rainloop/templates/personal_settings.php | 29 ++++++++++++++ 10 files changed, 163 insertions(+), 31 deletions(-) create mode 100644 rainloop/lib/Settings/AdminSettings.php create mode 100644 rainloop/lib/Settings/PersonalSettings.php mode change 100755 => 100644 rainloop/templates/personal.php create mode 100755 rainloop/templates/personal_settings.php diff --git a/rainloop/appinfo/app.php b/rainloop/appinfo/app.php index dc7b1b7e..b2bc8fa4 100644 --- a/rainloop/appinfo/app.php +++ b/rainloop/appinfo/app.php @@ -10,4 +10,6 @@ $app = new OCA\RainLoop\AppInfo\Application(); $app->registerNavigation(); +$app->registerPersonalSettings(); $app->getContainer()->query('RainLoopHelper')->registerHooks(); + diff --git a/rainloop/appinfo/info.xml b/rainloop/appinfo/info.xml index 4ab1741f..42cbeba1 100644 --- a/rainloop/appinfo/info.xml +++ b/rainloop/appinfo/info.xml @@ -21,6 +21,9 @@ - + + + OCA\RainLoop\Settings\AdminSettings + diff --git a/rainloop/lib/AppInfo/Application.php b/rainloop/lib/AppInfo/Application.php index 03453e50..671a9765 100644 --- a/rainloop/lib/AppInfo/Application.php +++ b/rainloop/lib/AppInfo/Application.php @@ -3,7 +3,9 @@ namespace OCA\RainLoop\AppInfo; use OCA\RainLoop\Util\RainLoopHelper; +use OCA\RainLoop\Controller\AjaxController; use OCA\RainLoop\Controller\PageController; +use OCA\RainLoop\Settings\PersonalSettings; use OCP\AppFramework\App; use OCP\IUser; @@ -31,6 +33,17 @@ public function __construct(array $urlParams = []) { } ); + $container->registerService( + 'AjaxController', function($c) { + return new AjaxController( + $c->query('AppName'), + $c->query('Request'), + $c->getServer()->getAppManager(), + $c->query('ServerContainer')->getConfig() + ); + } + ); + /** * Utils */ @@ -63,5 +76,9 @@ public function registerNavigation() { }); } + public function registerPersonalSettings() { + \OCP\App::registerPersonal('rainloop', 'templates/personal'); + } + } diff --git a/rainloop/lib/Controller/AjaxController.php b/rainloop/lib/Controller/AjaxController.php index 5850af90..8db3c3e7 100644 --- a/rainloop/lib/Controller/AjaxController.php +++ b/rainloop/lib/Controller/AjaxController.php @@ -1,14 +1,23 @@ -config = $config; + $this->appManager = $appManager; } public function setAdmin(): JSONResponse { @@ -18,10 +27,11 @@ public function setAdmin(): JSONResponse { $bAutologin = false; if (isset($_POST['appname']) && 'rainloop' === $_POST['appname']) { - OCP\IConfig::setAppValue('rainloop', 'rainloop-autologin', + $this->config->setAppValue('rainloop', 'rainloop-autologin', isset($_POST['rainloop-autologin']) ? '1' === $_POST['rainloop-autologin'] : false); - - $bAutologin = OCP\IConfig::getAppValue('rainloop', 'rainloop-autologin', false); + $this->config->setAppValue('rainloop', 'rainloop-autologin-with-email', + isset($_POST['rainloop-autologin']) ? '2' === $_POST['rainloop-autologin'] : false); + $bAutologin = $this->config->getAppValue('rainloop', 'rainloop-autologin', false); } else { return new JSONResponse([ 'status' => 'error', @@ -54,17 +64,17 @@ public function setPersonal(): JSONResponse { $sUser = \OC::$server->getUserSession()->getUser()->getUID(); $sPostEmail = $_POST['rainloop-email']; - OCP\IConfig::setUserValue($sUser, 'rainloop', 'rainloop-email', $sPostEmail); + $this->config->setUserValue($sUser, 'rainloop', 'rainloop-email', $sPostEmail); $sPass = $_POST['rainloop-password']; if ('******' !== $sPass && '' !== $sPass) { - include_once OCP\App\IAppManager::getAppPath('rainloop').'/lib/RainLoopHelper.php' + include_once $this->appManager->getAppPath('rainloop').'/lib/Util/RainLoopHelper.php'; - OCP\IConfig::setUserValue($sUser, 'rainloop', 'rainloop-password', - OC_RainLoop_Helper::encodePassword($sPass, md5($sPostEmail))); + $this->config->setUserValue($sUser, 'rainloop', 'rainloop-password', + RainLoopHelper::encodePassword($sPass, md5($sPostEmail))); } - $sEmail = OCP\IConfig::getUserValue($sUser, 'rainloop', 'rainloop-email', ''); + $sEmail = $this->config->getUserValue($sUser, 'rainloop', 'rainloop-email', ''); } else { return new JSONResponse([ 'status' => 'error', diff --git a/rainloop/lib/Controller/PageController.php b/rainloop/lib/Controller/PageController.php index d574d4d1..696b6b39 100644 --- a/rainloop/lib/Controller/PageController.php +++ b/rainloop/lib/Controller/PageController.php @@ -41,6 +41,10 @@ public function index() { $response = new TemplateResponse('rainloop', 'index', $params); + $csp = new ContentSecurityPolicy(); + $csp->addAllowedFrameDomain("'self'"); + $response->setContentSecurityPolicy($csp); + return $response; } diff --git a/rainloop/lib/Settings/AdminSettings.php b/rainloop/lib/Settings/AdminSettings.php new file mode 100644 index 00000000..6ba703b0 --- /dev/null +++ b/rainloop/lib/Settings/AdminSettings.php @@ -0,0 +1,45 @@ +config = $config; + } + + public function getForm() { + $keys = [ + 'rainloop-autologin', + 'rainloop-autologin-with-email' + ]; + + $parameters = []; + foreach ($keys as $k) { + $v = $this->config->getAppValue('rainloop', $k); + $parameters[$k] = $v; + } + + $uid = \OC::$server->getUserSession()->getUser()->getUID(); + if (\OC_User::isAdminUser($uid)) { + $parameters['rainloop-admin-panel-link'] = RainLoopHelper::getAppUrl().'?admin'; + } + + return new TemplateResponse('rainloop', 'admin-local', $parameters); + } + + public function getSection() { + return 'additional'; + } + + public function getPriority() { + return 50; + } + +} diff --git a/rainloop/lib/Settings/PersonalSettings.php b/rainloop/lib/Settings/PersonalSettings.php new file mode 100644 index 00000000..5c1d3d22 --- /dev/null +++ b/rainloop/lib/Settings/PersonalSettings.php @@ -0,0 +1,32 @@ +config = $config; + } + + public function getForm() { + $uid = \OC::$server->getUserSession()->getUser()->getUID(); + + $keys = [ + 'rainloop-email', + 'rainloop-password' + ]; + + $parameters = []; + foreach ($keys as $k) { + $v = $this->config->getUserValue($uid, 'rainloop', $k); + $parameters[$k] = $v; + } + + return new TemplateResponse('rainloop', 'personal_settings', $parameters); + } + +} + diff --git a/rainloop/templates/admin-local.php b/rainloop/templates/admin-local.php index 00139e67..c43c0f5e 100755 --- a/rainloop/templates/admin-local.php +++ b/rainloop/templates/admin-local.php @@ -1,3 +1,5 @@ + +
diff --git a/rainloop/templates/personal.php b/rainloop/templates/personal.php old mode 100755 new mode 100644 index ccadde9b..9d12c2a9 --- a/rainloop/templates/personal.php +++ b/rainloop/templates/personal.php @@ -1,20 +1,8 @@ -
- - - - -
-

t('RainLoop Webmail')); ?>

-

- - - - - -    -

-
- -
\ No newline at end of file +getContainer()->query(PersonalSettings::class); +return $controller->getForm()->render(); + diff --git a/rainloop/templates/personal_settings.php b/rainloop/templates/personal_settings.php new file mode 100755 index 00000000..c64b2f0c --- /dev/null +++ b/rainloop/templates/personal_settings.php @@ -0,0 +1,29 @@ + + +
+
+ + + +
+

t('RainLoop Webmail')); ?>

+

+ Enter an email and password to auto-login to RainLoop. Please note that this feature + may have some + security considerations. +

+

+ + + + + +    +

+
+
+
From 830efd81aef79d4e2db78c27f754074fd4e22a4f Mon Sep 17 00:00:00 2001 From: Nathan Kinkade Date: Thu, 14 May 2020 06:02:07 -0600 Subject: [PATCH 2/2] Removes an unused 'use'/import. --- rainloop/lib/AppInfo/Application.php | 1 - 1 file changed, 1 deletion(-) diff --git a/rainloop/lib/AppInfo/Application.php b/rainloop/lib/AppInfo/Application.php index 671a9765..e1a2d8f1 100644 --- a/rainloop/lib/AppInfo/Application.php +++ b/rainloop/lib/AppInfo/Application.php @@ -5,7 +5,6 @@ use OCA\RainLoop\Util\RainLoopHelper; use OCA\RainLoop\Controller\AjaxController; use OCA\RainLoop\Controller\PageController; -use OCA\RainLoop\Settings\PersonalSettings; use OCP\AppFramework\App; use OCP\IUser;