]> source.dussan.org Git - nextcloud-server.git/commitdiff
add a isLoggedIn method to the usersession and deprecate the isLoggedIn method on...
authorBernhard Posselt <dev@bernhard-posselt.com>
Tue, 16 Dec 2014 18:07:14 +0000 (19:07 +0100)
committerBernhard Posselt <dev@bernhard-posselt.com>
Tue, 16 Dec 2014 18:27:34 +0000 (19:27 +0100)
lib/private/appframework/dependencyinjection/dicontainer.php
lib/private/user/session.php
lib/public/appframework/iappcontainer.php
lib/public/iusersession.php
tests/lib/user/session.php

index 98525ed3202de24107c62cfec3cd7510366cd7be..3ed8a583b819978d4ad532c1cb328d9131fe3821 100644 (file)
@@ -187,6 +187,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{
        }
 
        /**
+        * @deprecated use IUserSession->isLoggedIn()
         * @return boolean
         */
        function isLoggedIn() {
index 277aa1a047e8b58c48bf21377bf09f2ac1c8bcd9..53662d00952244738f34f57a2b311282603204f6 100644 (file)
@@ -137,6 +137,15 @@ class Session implements IUserSession, Emitter {
                }
        }
 
+       /**
+        * Checks wether the user is logged in
+        *
+        * @return bool if logged in
+        */
+       public function isLoggedIn() {
+               return $this->getUser() !== null;
+       }
+
        /**
         * set the login name
         *
index a0b0c06881a856fdd88d7f8b055670de1dc16946..ad8e5a2214bdfb623c5d94ad29af3992cfbf3481 100644 (file)
@@ -31,7 +31,7 @@ use OCP\IContainer;
  *
  * This container interface provides short cuts for app developers to access predefined app service.
  */
-interface IAppContainer extends IContainer{
+interface IAppContainer extends IContainer {
 
        /**
         * used to return the appname of the set application
@@ -56,6 +56,7 @@ interface IAppContainer extends IContainer{
        function registerMiddleWare($middleWare);
 
        /**
+        * @deprecated use IUserSession->isLoggedIn()
         * @return boolean
         */
        function isLoggedIn();
index db4abe150d2bf78c6fee2cdb7c245055e8207219..4c5b4d1ba51cf8556929180283cfa204c2629643 100644 (file)
@@ -3,7 +3,9 @@
  * ownCloud
  *
  * @author Bart Visscher
+ * @author Bernhard Posselt
  * @copyright 2013 Bart Visscher bartv@thisnet.nl
+ * @copyright 2014 Bernhard Posselt <dev@bernhard-posselt.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -62,4 +64,11 @@ interface IUserSession {
         * @return \OCP\IUser
         */
        public function getUser();
+
+       /**
+        * Checks wether the user is logged in
+        *
+        * @return bool if logged in
+        */
+       public function isLoggedIn();
 }
index aa1ea5841c0573c49c3fcd9796f4c643211e6c7c..d441f8020879234fcdf9220bcb61f831dbb3481c 100644 (file)
@@ -34,6 +34,34 @@ class Session extends \Test\TestCase {
                $this->assertEquals('foo', $user->getUID());
        }
 
+       public function testIsLoggedIn() {
+               $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+               $session->expects($this->once())
+                       ->method('get')
+                       ->with('user_id')
+                       ->will($this->returnValue(null));
+
+               $backend = $this->getMock('OC_User_Dummy');
+               $backend->expects($this->once())
+                       ->method('userExists')
+                       ->with('foo')
+                       ->will($this->returnValue(true));
+
+               $manager = new \OC\User\Manager();
+               $manager->registerBackend($backend);
+
+               $userSession = new \OC\User\Session($manager, $session);
+               $isLoggedIn = $userSession->isLoggedIn();
+               $this->assertFalse($isLoggedIn);
+
+               $session->expects($this->once())
+                       ->method('get')
+                       ->with('user_id')
+                       ->will($this->returnValue('foo'));
+               $isLoggedIn = $userSession->isLoggedIn();
+               $this->assertTrue($isLoggedIn);
+       }
+
        public function testSetUser() {
                $session = $this->getMock('\OC\Session\Memory', array(), array(''));
                $session->expects($this->once())