diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-16 19:07:14 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-17 17:40:52 +0100 |
commit | 236632702cf7fe68cc9ad1dcfcc463e0d4c14d64 (patch) | |
tree | 17acbbe2628c91836fdf662832cbaa1929f036eb | |
parent | a641bb75926ba20befe1d4bfb75c4a8025684f69 (diff) | |
download | nextcloud-server-236632702cf7fe68cc9ad1dcfcc463e0d4c14d64.tar.gz nextcloud-server-236632702cf7fe68cc9ad1dcfcc463e0d4c14d64.zip |
add a isLoggedIn method to the usersession and deprecate the isLoggedIn method on the api
-rw-r--r-- | lib/private/appframework/dependencyinjection/dicontainer.php | 1 | ||||
-rw-r--r-- | lib/private/user/session.php | 9 | ||||
-rw-r--r-- | lib/public/appframework/iappcontainer.php | 3 | ||||
-rw-r--r-- | lib/public/iusersession.php | 9 | ||||
-rw-r--r-- | tests/lib/user/session.php | 28 |
5 files changed, 49 insertions, 1 deletions
diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php index 517ada2d205..faab40ce246 100644 --- a/lib/private/appframework/dependencyinjection/dicontainer.php +++ b/lib/private/appframework/dependencyinjection/dicontainer.php @@ -188,6 +188,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** + * @deprecated use IUserSession->isLoggedIn() * @return boolean */ function isLoggedIn() { diff --git a/lib/private/user/session.php b/lib/private/user/session.php index 277aa1a047e..53662d00952 100644 --- a/lib/private/user/session.php +++ b/lib/private/user/session.php @@ -138,6 +138,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 * * @param string|null $loginName for the logged in user diff --git a/lib/public/appframework/iappcontainer.php b/lib/public/appframework/iappcontainer.php index 3621d69a542..2270b17c5b7 100644 --- a/lib/public/appframework/iappcontainer.php +++ b/lib/public/appframework/iappcontainer.php @@ -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 @@ -57,6 +57,7 @@ interface IAppContainer extends IContainer{ function registerMiddleWare($middleWare); /** + * @deprecated use IUserSession->isLoggedIn() * @return boolean */ function isLoggedIn(); diff --git a/lib/public/iusersession.php b/lib/public/iusersession.php index db4abe150d2..4c5b4d1ba51 100644 --- a/lib/public/iusersession.php +++ b/lib/public/iusersession.php @@ -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(); } diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php index aa1ea5841c0..d441f802087 100644 --- a/tests/lib/user/session.php +++ b/tests/lib/user/session.php @@ -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()) |