]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use AppFramework instead of custom controller
authorLukas Reschke <lukas@owncloud.com>
Fri, 22 Aug 2014 16:16:55 +0000 (18:16 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Mon, 25 Aug 2014 09:50:19 +0000 (11:50 +0200)
apps/files_external/js/settings.js
core/application.php [new file with mode: 0644]
core/lostpassword/application.php [deleted file]
core/routes.php
core/user/controller.php [deleted file]
core/user/usercontroller.php [new file with mode: 0644]

index 27ed0254dd3d739acfe9c8297b915c061afedae2..6c287d6a7603931bf03b93864a3631f55b74dd19 100644 (file)
@@ -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/application.php b/core/application.php
new file mode 100644 (file)
index 0000000..3380184
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @author Victor Dubiniuk
+ * @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Core;
+
+use \OCP\AppFramework\App;
+use OC\Core\LostPassword\Controller\LostController;
+use OC\Core\User\UserController;
+
+class Application extends App {
+
+
+       public function __construct(array $urlParams=array()){
+               parent::__construct('core', $urlParams);
+
+               $container = $this->getContainer();
+
+               /**
+                * Controllers
+                */
+               $container->registerService('LostController', function($c) {
+                       return new LostController(
+                               $c->query('AppName'),
+                               $c->query('Request'),
+                               $c->query('ServerContainer')->getURLGenerator(),
+                               $c->query('ServerContainer')->getUserManager(),
+                               new \OC_Defaults(),
+                               $c->query('ServerContainer')->getL10N('core'),
+                               $c->query('ServerContainer')->getConfig(),
+                               $c->query('ServerContainer')->getUserSession(),
+                               \OCP\Util::getDefaultEmailAddress('lostpassword-noreply'),
+                               \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/lostpassword/application.php b/core/lostpassword/application.php
deleted file mode 100644 (file)
index ba2f3fc..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/**
- * @author Victor Dubiniuk
- * @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace OC\Core\LostPassword;
-
-use \OCP\AppFramework\App;
-use OC\Core\LostPassword\Controller\LostController;
-
-class Application extends App {
-
-
-       public function __construct(array $urlParams=array()){
-               parent::__construct('core', $urlParams);
-
-               $container = $this->getContainer();
-
-               /**
-                * Controllers
-                */
-               $container->registerService('LostController', function($c) {
-                       return new LostController(
-                               $c->query('AppName'),
-                               $c->query('Request'),
-                               $c->query('ServerContainer')->getURLGenerator(),
-                               $c->query('ServerContainer')->getUserManager(),
-                               new \OC_Defaults(),
-                               $c->query('ServerContainer')->getL10N('core'),
-                               $c->query('ServerContainer')->getConfig(),
-                               $c->query('ServerContainer')->getUserSession(),
-                               \OCP\Util::getDefaultEmailAddress('lostpassword-noreply'),
-                               \OC_App::isEnabled('files_encryption')
-                       );
-               });
-       }
-
-
-}
index 37eb2f8a56cc29eaf4e1f5713468df27211accbb..28a3680dd91a382db1d8d1b137968049013aa39f 100644 (file)
@@ -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 (file)
index cbcbd93..0000000
+++ /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 (file)
index 0000000..2570e3b
--- /dev/null
@@ -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);
+
+       }
+}