From f33312f76773a46acf084dd93830c739e44e9962 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Fri, 22 Aug 2014 18:16:55 +0200 Subject: Use AppFramework instead of custom controller --- core/user/controller.php | 31 --------------------- core/user/usercontroller.php | 66 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 31 deletions(-) delete mode 100644 core/user/controller.php create mode 100644 core/user/usercontroller.php (limited to 'core/user') diff --git a/core/user/controller.php b/core/user/controller.php deleted file mode 100644 index cbcbd936183..00000000000 --- a/core/user/controller.php +++ /dev/null @@ -1,31 +0,0 @@ - - * 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)); - } -} diff --git a/core/user/usercontroller.php b/core/user/usercontroller.php new file mode 100644 index 00000000000..2570e3b5b05 --- /dev/null +++ b/core/user/usercontroller.php @@ -0,0 +1,66 @@ + + * Copyright (c) 2014 Lukas Reschke + * 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); + + } +} -- cgit v1.2.3