add a isLoggedIn method to the usersession and deprecate the isLoggedIn method on the api
This commit is contained in:
parent
a641bb7592
commit
236632702c
|
@ -188,6 +188,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated use IUserSession->isLoggedIn()
|
||||
* @return boolean
|
||||
*/
|
||||
function isLoggedIn() {
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -57,6 +57,7 @@ interface IAppContainer extends IContainer{
|
|||
function registerMiddleWare($middleWare);
|
||||
|
||||
/**
|
||||
* @deprecated use IUserSession->isLoggedIn()
|
||||
* @return boolean
|
||||
*/
|
||||
function isLoggedIn();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue