Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #156 from nkinkade/app-framework
Browse files Browse the repository at this point in the history
Gets admin and personal settings working again
  • Loading branch information
pierre-alain-b authored May 17, 2020
2 parents 9391e0d + 89f612d commit 7289ba7
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 35 deletions.
2 changes: 2 additions & 0 deletions rainloop/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

$app = new OCA\RainLoop\AppInfo\Application();
$app->registerNavigation();
$app->registerPersonalSettings();
$app->getContainer()->query('RainLoopHelper')->registerHooks();

13 changes: 8 additions & 5 deletions rainloop/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
<version>6.1.4</version>
<licence>agpl</licence>
<author>RainLoop Team, Nextgen-Networks, Tab Fitts, Nathan Kinkade, Pierre-Alain Bandinelli</author>
<dependencies>
<php min-version="5.4" />
<owncloud min-version="6" max-version="9.2" />
<nextcloud min-version="19" max-version="19" />
</dependencies>
<namespace>RainLoop</namespace>
<documentation>
<user>https://github.com/pierre-alain-b/rainloop-nextcloud/blob/master/README.md</user>
Expand All @@ -23,4 +18,12 @@
<website>https://github.com/pierre-alain-b/rainloop-nextcloud</website>
<bugs>https://github.com/pierre-alain-b/rainloop-nextcloud/issues</bugs>
<screenshot>https://raw.githubusercontent.com/pierre-alain-b/rainloop-nextcloud/master/screenshots/2016.10.20-screenshot.jpg</screenshot>
<dependencies>
<php min-version="5.4" />
<owncloud min-version="6" max-version="9.2" />
<nextcloud min-version="19" max-version="19" />
</dependencies>
<settings>
<admin>OCA\RainLoop\Settings\AdminSettings</admin>
</settings>
</info>
16 changes: 16 additions & 0 deletions rainloop/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OCA\RainLoop\AppInfo;

use OCA\RainLoop\Util\RainLoopHelper;
use OCA\RainLoop\Controller\AjaxController;
use OCA\RainLoop\Controller\PageController;

use OCP\AppFramework\App;
Expand Down Expand Up @@ -31,6 +32,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
*/
Expand Down Expand Up @@ -63,5 +75,9 @@ public function registerNavigation() {
});
}

public function registerPersonalSettings() {
\OCP\App::registerPersonal('rainloop', 'templates/personal');
}

}

30 changes: 20 additions & 10 deletions rainloop/lib/Controller/AjaxController.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
<? php
<?php

namespace OCA\RainLoop\Controller;

use OCA\RainLoop\Util\RainLoopHelper;

use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IRequest;

class AjaxController extends Controller {
public function __construct(string $appName, IRequest $request) {
private $config;
private $appManager;

public function __construct(string $appName, IRequest $request, IAppManager $appManager, IConfig $config) {
parent::__construct($appName, $request);
$this->config = $config;
$this->appManager = $appManager;
}

public function setAdmin(): JSONResponse {
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions rainloop/lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function index() {

$response = new TemplateResponse('rainloop', 'index', $params);

$csp = new ContentSecurityPolicy();
$csp->addAllowedFrameDomain("'self'");
$response->setContentSecurityPolicy($csp);

return $response;
}

Expand Down
45 changes: 45 additions & 0 deletions rainloop/lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace OCA\RainLoop\Settings;

use OCA\RainLoop\Util\RainLoopHelper;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Settings\ISettings;

class AdminSettings implements ISettings {

private $config;

public function __construct(IConfig $config) {
$this->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;
}

}
32 changes: 32 additions & 0 deletions rainloop/lib/Settings/PersonalSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace OCA\RainLoop\Settings;

use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;

class PersonalSettings {
private $config;

public function __construct(IConfig $config) {
$this->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);
}

}

2 changes: 2 additions & 0 deletions rainloop/templates/admin-local.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php script('rainloop', 'admin') ?>

<div class="section">
<form id="mail-rainloop-admin-form" action="#" method="post">
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
Expand Down
28 changes: 8 additions & 20 deletions rainloop/templates/personal.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
<div class="section">
<form id="mail-rainloop-personal-form" action="#" method="post">
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
<input type="hidden" name="appname" value="rainloop">

<fieldset class="personalblock">
<h2><?php p($l->t('RainLoop Webmail')); ?></h2>
<p>
<input type="text" id="rainloop-email" name="rainloop-email"
value="<?php echo $_['rainloop-email']; ?>" placeholder="<?php p($l->t('Email')); ?>" />

<input type="password" id="rainloop-password" name="rainloop-password"
value="<?php echo $_['rainloop-password']; ?>" placeholder="<?php p($l->t('Password')); ?>" />

<input type="button" id="rainloop-save-button" name="rainloop-save-button" value="<?php p($l->t('Save')); ?>" />
&nbsp;&nbsp;<span class="rainloop-result-desc"></span>
</p>
</fieldset>
</form>
</div>
<?php

use OCA\RainLoop\Settings\PersonalSettings;

$app = new \OCA\RainLoop\AppInfo\Application();
$controller = $app->getContainer()->query(PersonalSettings::class);
return $controller->getForm()->render();

29 changes: 29 additions & 0 deletions rainloop/templates/personal_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php script('rainloop', 'personal') ?>

<div class="section">
<form id="mail-rainloop-personal-form" action="#" method="post">
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
<input type="hidden" name="appname" value="rainloop">

<fieldset class="personalblock">
<h2><?php p($l->t('RainLoop Webmail')); ?></h2>
<p>
Enter an email and password to auto-login to RainLoop. <b>Please note</b> that this feature
<a href="https://github.com/pierre-alain-b/rainloop-nextcloud/issues/87"
style="color:blue; text-decoration:underline" target="_blank">may have some</a>
<a href="https://github.com/RainLoop/rainloop-webmail/issues/1082"
style="color:blue; text-decoration:underline" target="_blank">security considerations</a>.
</p>
<p>
<input type="text" id="rainloop-email" name="rainloop-email"
value="<?php echo $_['rainloop-email']; ?>" placeholder="<?php p($l->t('Email')); ?>" />

<input type="password" id="rainloop-password" name="rainloop-password"
value="<?php echo $_['rainloop-password']; ?>" placeholder="<?php p($l->t('Password')); ?>" />

<input type="button" id="rainloop-save-button" name="rainloop-save-button" value="<?php p($l->t('Save')); ?>" />
&nbsp;&nbsp;<span class="rainloop-result-desc"></span>
</p>
</fieldset>
</form>
</div>

0 comments on commit 7289ba7

Please sign in to comment.