summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-08-22 18:16:55 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-08-25 11:50:19 +0200
commitf33312f76773a46acf084dd93830c739e44e9962 (patch)
tree4caa766b1d11ac1087b81f2d648f59f92194c1a1
parent6202ef3258c7db707f32c0bcaa17552b92fa15eb (diff)
downloadnextcloud-server-f33312f76773a46acf084dd93830c739e44e9962.tar.gz
nextcloud-server-f33312f76773a46acf084dd93830c739e44e9962.zip
Use AppFramework instead of custom controller
-rw-r--r--apps/files_external/js/settings.js13
-rw-r--r--core/application.php (renamed from core/lostpassword/application.php)11
-rw-r--r--core/routes.php7
-rw-r--r--core/user/controller.php31
-rw-r--r--core/user/usercontroller.php66
5 files changed, 88 insertions, 40 deletions
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js
index 27ed0254dd3..6c287d6a760 100644
--- a/apps/files_external/js/settings.js
+++ b/apps/files_external/js/settings.js
@@ -233,10 +233,17 @@ $(document).ready(function() {
}
},
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'), {
- data: {
- users: element.val().split(",")
- },
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify(users),
dataType: "json"
}).done(function(data) {
var results = [];
diff --git a/core/lostpassword/application.php b/core/application.php
index ba2f3fc633b..33801847758 100644
--- a/core/lostpassword/application.php
+++ b/core/application.php
@@ -8,10 +8,11 @@
* See the COPYING-README file.
*/
-namespace OC\Core\LostPassword;
+namespace OC\Core;
use \OCP\AppFramework\App;
use OC\Core\LostPassword\Controller\LostController;
+use OC\Core\User\UserController;
class Application extends App {
@@ -38,6 +39,14 @@ class Application extends App {
\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()
+ );
+ });
}
diff --git a/core/routes.php b/core/routes.php
index 37eb2f8a56c..28a3680dd91 100644
--- a/core/routes.php
+++ b/core/routes.php
@@ -6,13 +6,14 @@
* See the COPYING-README file.
*/
-use OC\Core\LostPassword\Application;
+use OC\Core\Application;
$application = new Application();
$application->registerRoutes($this, array('routes' => array(
array('name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'),
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' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'),
)
));
@@ -35,10 +36,6 @@ $this->create('core_ajax_share', '/core/ajax/share.php')
// Translations
$this->create('core_ajax_translations', '/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
$this->create('core_tags_tags', '/tags/{type}')
->get()
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 @@
-<?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));
- }
-}
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 @@
+<?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);
+
+ }
+}