[Pkg-owncloud-commits] [owncloud-doc] 73/270: add users and session management

David Prévot taffit at moszumanska.debian.org
Thu Jul 31 03:53:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud-doc.

commit 424bc9911fd2a722b07f0509236715daf85f96af
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date:   Mon May 12 01:53:49 2014 +0200

    add users and session management
---
 developer_manual/app/users.rst | 169 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 168 insertions(+), 1 deletion(-)

diff --git a/developer_manual/app/users.rst b/developer_manual/app/users.rst
index 304b590..77c6b29 100644
--- a/developer_manual/app/users.rst
+++ b/developer_manual/app/users.rst
@@ -2,4 +2,171 @@
 User & Session Management
 =========================
 
-.. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
\ No newline at end of file
+.. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
+
+Users can be managed using the UserManager which is injected from the ServerContainer:
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\AppInfo;
+
+    use \OCP\AppFramework\App;
+
+    use \OCA\MyApp\Service\UserService;
+
+
+    class Application extends App {
+
+        public function __construct(array $urlParams=array()){
+            parent::__construct('myapp', $urlParams);
+
+            $container = $this->getContainer();
+
+            /**
+             * Controllers
+             */
+            $container->registerService('UserService', function($c) {
+                return new UserService(
+                    $c->query('UserManager')
+                );
+            });
+
+            $container->registerService('UserManager', function($c) {
+                return $c->query('ServerContainer')->getUserManager();
+            });
+        }
+    }
+
+
+
+Creating users
+==============
+Creating a user is done by passing a username and password to the create method:
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Service;
+
+    class UserService {
+
+        private $userManager;
+
+        public function __construct($userManager){
+            $this->userManager = $userManager;
+        }
+
+        public function create($userId, $password) {
+            return $this->userManager->create($userId, $password);
+        }
+
+    }
+
+Modifying users
+===============
+Users can be modified by getting a user by the userId or by a search pattern. The returned user objects can then be used to:
+
+* Delete them
+* Set a new password
+* Disable/Enable them
+* Get their home directory
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Service;
+
+    class UserService {
+
+        private $userManager;
+
+        public function __construct($userManager){
+            $this->userManager = $userManager;
+        }
+
+        public function delete($userId) {
+            return $this->userManager->get($userId)->delete();
+        }
+
+        // recoveryPassword is used for the encryption app to recover the keys
+        public function setPassword($userId, $password, $recoveryPassword) {
+            return $this->userManager->get($userId)->setPassword($password, $recoveryPassword);
+        }
+
+        public function disable($userId) {
+            return $this->userManager->get($userId)->setEnabled(false);
+        }
+
+        public function getHome($userId) {
+            return $this->userManager->get($userId)->getHome();   
+        }
+    }
+
+Session Information
+===================
+To login, logout or getting the currently logged in user, the Session has to be injected from the ServerContainer:
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\AppInfo;
+
+    use \OCP\AppFramework\App;
+
+    use \OCA\MyApp\Service\UserService;
+
+
+    class Application extends App {
+
+        public function __construct(array $urlParams=array()){
+            parent::__construct('myapp', $urlParams);
+
+            $container = $this->getContainer();
+
+            /**
+             * Controllers
+             */
+            $container->registerService('UserService', function($c) {
+                return new UserService(
+                    $c->query('Session')
+                );
+            });
+
+            $container->registerService('Session', function($c) {
+                return $c->query('ServerContainer')->getSession();
+            });
+
+            // currently logged in user, userId can be gotten by calling the
+            // getUID() method on it
+            $container->registerService('User', function($c) {
+                return $c->query('Session')->getUser();
+            });
+        }
+    }
+
+
+Then users can be logged in by using:
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Service;
+
+    class UserService {
+
+        private $session;
+
+        public function __construct($session){
+            $this->session = $session;
+        }
+
+        public function login($userId, $password) {
+            return $this->session->login($userId, $password);
+        }
+
+        public function logout() {
+            $this->session->logout();
+        }
+
+    }
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-doc.git



More information about the Pkg-owncloud-commits mailing list