Update# admin page section
This commit is contained in:
parent
a88e27ba85
commit
1f9d55ae1d
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ownCloud - registration
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later. See the COPYING file.
|
||||||
|
*
|
||||||
|
* @author Pellaeon Lin <pellaeon@cnmc.tw>
|
||||||
|
* @copyright Pellaeon Lin 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Registration\App;
|
||||||
|
|
||||||
|
$app = new Registration();
|
||||||
|
$controller = $app->getContainer()->query('SettingsController');
|
||||||
|
return $controller->displayPanel()->render();
|
||||||
|
|
@ -11,10 +11,10 @@
|
||||||
|
|
||||||
namespace OCA\Registration\App;
|
namespace OCA\Registration\App;
|
||||||
|
|
||||||
|
|
||||||
use \OCP\AppFramework\App;
|
use \OCP\AppFramework\App;
|
||||||
|
|
||||||
use \OCA\Registration\Controller\RegisterController;
|
use \OCA\Registration\Controller\RegisterController;
|
||||||
|
use \OCA\Registration\Controller\SettingsController;
|
||||||
use \OCA\Registration\Wrapper;
|
use \OCA\Registration\Wrapper;
|
||||||
use \OCA\Registration\Db\PendingRegist;
|
use \OCA\Registration\Db\PendingRegist;
|
||||||
|
|
||||||
|
|
@ -42,6 +42,16 @@ class Registration extends App {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$container->registerService('SettingsController', function($c) {
|
||||||
|
return new SettingsController(
|
||||||
|
$c->query('AppName'),
|
||||||
|
$c->query('Request'),
|
||||||
|
$c->query('L10N'),
|
||||||
|
$c->query('Config'),
|
||||||
|
$c->query('GroupManager')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core
|
* Core
|
||||||
|
|
@ -54,6 +64,10 @@ class Registration extends App {
|
||||||
return $c->query('ServerContainer')->getUserManager();
|
return $c->query('ServerContainer')->getUserManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$container->registerService('GroupManager', function($c) {
|
||||||
|
return $c->query('ServerContainer')->getGroupManager();
|
||||||
|
});
|
||||||
|
|
||||||
$container->registerService('Config', function($c) {
|
$container->registerService('Config', function($c) {
|
||||||
return $c->query('ServerContainer')->getConfig();
|
return $c->query('ServerContainer')->getConfig();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,5 @@ $app = new Registration();
|
||||||
$c = $app->getContainer();
|
$c = $app->getContainer();
|
||||||
|
|
||||||
\OC_App::registerLogIn(array('name' => $c->query('L10N')->t('Register'), 'href' => $c->query('URLGenerator')->linkToRoute('registration.register.askEmail')));
|
\OC_App::registerLogIn(array('name' => $c->query('L10N')->t('Register'), 'href' => $c->query('URLGenerator')->linkToRoute('registration.register.askEmail')));
|
||||||
|
|
||||||
|
\OCP\App::registerAdmin($c->getAppName(), 'admin');
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ namespace OCA\Registration\App;
|
||||||
$application = new Registration();
|
$application = new Registration();
|
||||||
|
|
||||||
$application->registerRoutes($this, array('routes' => array(
|
$application->registerRoutes($this, array('routes' => array(
|
||||||
|
array('name' => 'settings#admin', 'url' => '/settings', 'verb' => 'POST'),
|
||||||
array('name' => 'register#askEmail', 'url' => '/', 'verb' => 'GET'),
|
array('name' => 'register#askEmail', 'url' => '/', 'verb' => 'GET'),
|
||||||
array('name' => 'register#validateEmail', 'url' => '/', 'verb' => 'POST'),
|
array('name' => 'register#validateEmail', 'url' => '/', 'verb' => 'POST'),
|
||||||
array('name' => 'register#verifyToken', 'url' => '/verify/{token}', 'verb' => 'GET'),
|
array('name' => 'register#verifyToken', 'url' => '/verify/{token}', 'verb' => 'GET'),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ownCloud - registration
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later. See the COPYING file.
|
||||||
|
*
|
||||||
|
* @author Pellaeon Lin <pellaeon@cnmc.tw>
|
||||||
|
* @copyright Pellaeon Lin 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Registration\Controller;
|
||||||
|
|
||||||
|
use \OCP\IRequest;
|
||||||
|
use \OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use \OCP\AppFramework\Http\DataResponse;
|
||||||
|
use \OCP\AppFramework\Http;
|
||||||
|
use \OCP\AppFramework\Controller;
|
||||||
|
use \OCP\IUserManager;
|
||||||
|
use \OCP\IGroupManager;
|
||||||
|
use \OCP\IL10N;
|
||||||
|
use \OCP\IConfig;
|
||||||
|
use \OCP\IUser;
|
||||||
|
|
||||||
|
class SettingsController extends Controller {
|
||||||
|
|
||||||
|
private $l10n;
|
||||||
|
private $config;
|
||||||
|
private $groupmanager;
|
||||||
|
protected $appName;
|
||||||
|
|
||||||
|
public function __construct($appName, IRequest $request, IL10N $l10n, IConfig $config, IGroupManager $groupmanager){
|
||||||
|
$this->l10n = $l10n;
|
||||||
|
$this->config = $config;
|
||||||
|
$this->groupmanager = $groupmanager;
|
||||||
|
$this->appName = $appName;
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @AdminRequired
|
||||||
|
*
|
||||||
|
* @param string $registered_user_group all newly registered user will be put in this group
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function admin($registered_user_group) {
|
||||||
|
$groups = $this->groupmanager->search('');
|
||||||
|
foreach ( $groups as $group ) {
|
||||||
|
$group_id_list[] = $group->getGid();
|
||||||
|
}
|
||||||
|
if ( in_array($registered_user_group, $group_id_list) ) {
|
||||||
|
$this->config->setAppValue($this->appName, 'registered_user_group', $registered_user_group);
|
||||||
|
return new DataResponse(array(
|
||||||
|
'data' => array(
|
||||||
|
'message' => (string) $this->l10n->t('Your settings have been updated.'),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
return new DataResponse(array(
|
||||||
|
'data' => array(
|
||||||
|
'message' => (string) $this->l10n->t('No such group'),
|
||||||
|
),
|
||||||
|
), Http::STATUS_NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @AdminRequired
|
||||||
|
*
|
||||||
|
* @return TemplateResponse
|
||||||
|
*/
|
||||||
|
public function displayPanel() {
|
||||||
|
$groups = $this->groupmanager->search('');
|
||||||
|
foreach ( $groups as $group ) {
|
||||||
|
$group_id_list[] = $group->getGid();
|
||||||
|
}
|
||||||
|
return new TemplateResponse('registration', 'admin', [
|
||||||
|
'groups' => $group_id_list
|
||||||
|
], '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
$(document).ready(function() {
|
||||||
|
function saveSettings() {
|
||||||
|
var post = $('#registered_user_group').serialize();
|
||||||
|
|
||||||
|
$.post(OC.generateUrl('/apps/registration/settings'), post);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#registered_user_group').change(saveSettings);
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
script('registration', 'settings');
|
||||||
|
?>
|
||||||
|
<form id="registration" class="section">
|
||||||
|
<h2><?php p($l->t('Registration')); ?></h2>
|
||||||
|
<p>
|
||||||
|
<label for="registered_user_group"><?php p($l->t('Default group that all registered users belong')); ?></label>
|
||||||
|
<select id="registered_user_group" name="registered_user_group">
|
||||||
|
<option value="none"><?php p($l->t('None')); ?></option>
|
||||||
|
<?php
|
||||||
|
foreach ( $_['groups'] as $group ) {
|
||||||
|
echo '<option value="'.$group.'">'.$group.'</option>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
Loading…
Reference in New Issue