Use AppFramework instead of custom controller
This commit is contained in:
parent
6202ef3258
commit
f33312f767
|
@ -233,10 +233,17 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
initSelection: function(element, callback) {
|
initSelection: function(element, callback) {
|
||||||
|
var users = {};
|
||||||
|
users['users'] = [];
|
||||||
|
var toSplit = element.val().split(",");
|
||||||
|
for (var i = 0; i < toSplit.length; i++) {
|
||||||
|
users['users'].push(toSplit[i]);
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax(OC.generateUrl('displaynames'), {
|
$.ajax(OC.generateUrl('displaynames'), {
|
||||||
data: {
|
type: 'POST',
|
||||||
users: element.val().split(",")
|
contentType: 'application/json',
|
||||||
},
|
data: JSON.stringify(users),
|
||||||
dataType: "json"
|
dataType: "json"
|
||||||
}).done(function(data) {
|
}).done(function(data) {
|
||||||
var results = [];
|
var results = [];
|
||||||
|
|
|
@ -8,10 +8,11 @@
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OC\Core\LostPassword;
|
namespace OC\Core;
|
||||||
|
|
||||||
use \OCP\AppFramework\App;
|
use \OCP\AppFramework\App;
|
||||||
use OC\Core\LostPassword\Controller\LostController;
|
use OC\Core\LostPassword\Controller\LostController;
|
||||||
|
use OC\Core\User\UserController;
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App {
|
||||||
|
|
||||||
|
@ -38,6 +39,14 @@ class Application extends App {
|
||||||
\OC_App::isEnabled('files_encryption')
|
\OC_App::isEnabled('files_encryption')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
$container->registerService('UserController', function($c) {
|
||||||
|
return new UserController(
|
||||||
|
$c->query('AppName'),
|
||||||
|
$c->query('Request'),
|
||||||
|
$c->query('ServerContainer')->getUserManager(),
|
||||||
|
new \OC_Defaults()
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,14 @@
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use OC\Core\LostPassword\Application;
|
use OC\Core\Application;
|
||||||
|
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
$application->registerRoutes($this, array('routes' => array(
|
$application->registerRoutes($this, array('routes' => array(
|
||||||
array('name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'),
|
array('name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'),
|
||||||
array('name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'),
|
array('name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'),
|
||||||
array('name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'),
|
array('name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'),
|
||||||
|
array('name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'),
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -35,10 +36,6 @@ $this->create('core_ajax_share', '/core/ajax/share.php')
|
||||||
// Translations
|
// Translations
|
||||||
$this->create('core_ajax_translations', '/core/ajax/translations.php')
|
$this->create('core_ajax_translations', '/core/ajax/translations.php')
|
||||||
->actionInclude('core/ajax/translations.php');
|
->actionInclude('core/ajax/translations.php');
|
||||||
// User display names
|
|
||||||
$this->create('core_user_displaynames', '/displaynames')
|
|
||||||
->get()
|
|
||||||
->action('OC\Core\User\Controller', 'getDisplayNames');
|
|
||||||
// Tags
|
// Tags
|
||||||
$this->create('core_tags_tags', '/tags/{type}')
|
$this->create('core_tags_tags', '/tags/{type}')
|
||||||
->get()
|
->get()
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Copyright (c) 2014 Jörn Dreyer <jfd@owncloud.com>
|
|
||||||
* This file is licensed under the Affero General Public License version 3 or
|
|
||||||
* later.
|
|
||||||
* See the COPYING-README file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace OC\Core\User;
|
|
||||||
|
|
||||||
class Controller {
|
|
||||||
public static function getDisplayNames($args) {
|
|
||||||
\OC_JSON::checkLoggedIn();
|
|
||||||
\OC_JSON::callCheck();
|
|
||||||
|
|
||||||
$users = $_GET['users'];
|
|
||||||
$result = array();
|
|
||||||
$userManager = \OC::$server->getUserManager();
|
|
||||||
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$userObject = $userManager->get($user);
|
|
||||||
if (is_object($userObject)) {
|
|
||||||
$result[$user] = $userObject->getDisplayName();
|
|
||||||
} else {
|
|
||||||
$result[$user] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
\OC_JSON::success(array('users'=>$result));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014 Jörn Dreyer <jfd@owncloud.com>
|
||||||
|
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OC\Core\User;
|
||||||
|
|
||||||
|
use \OCP\AppFramework\Controller;
|
||||||
|
use \OCP\AppFramework\Http\JSONResponse;
|
||||||
|
use \OCP\IRequest;
|
||||||
|
|
||||||
|
class UserController extends Controller {
|
||||||
|
/**
|
||||||
|
* @var \OCP\IUserManager
|
||||||
|
*/
|
||||||
|
protected $userManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \OC_Defaults
|
||||||
|
*/
|
||||||
|
protected $defaults;
|
||||||
|
|
||||||
|
public function __construct($appName,
|
||||||
|
IRequest $request,
|
||||||
|
$userManager,
|
||||||
|
$defaults
|
||||||
|
) {
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
$this->userManager = $userManager;
|
||||||
|
$this->defaults = $defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup user display names
|
||||||
|
*
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param array $users
|
||||||
|
*
|
||||||
|
* @return JSONResponse
|
||||||
|
*/
|
||||||
|
public function getDisplayNames($users) {
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$userObject = $this->userManager->get($user);
|
||||||
|
if (is_object($userObject)) {
|
||||||
|
$result[$user] = $userObject->getDisplayName();
|
||||||
|
} else {
|
||||||
|
$result[$user] = $user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = array(
|
||||||
|
'users' => $result,
|
||||||
|
'status' => 'success'
|
||||||
|
);
|
||||||
|
|
||||||
|
return new JSONResponse($json);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue