mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 10:23:17 +00:00
Fix disconnection on session delete
This commit is contained in:
@@ -149,6 +149,19 @@ class Authenticator
|
|||||||
*/
|
*/
|
||||||
public function isAuthenticated()
|
public function isAuthenticated()
|
||||||
{
|
{
|
||||||
return $this->session->has('usr_id');
|
if (!$this->session->has('usr_id')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->session->has('session_id')) {
|
||||||
|
if (null !== $this->em->find('Entities\Session', $this->session->get('session_id'))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->session->invalidate();
|
||||||
|
$this->reinitUser();
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,8 +113,7 @@ class Installer
|
|||||||
private function createUser($email, $password)
|
private function createUser($email, $password)
|
||||||
{
|
{
|
||||||
$user = \User_Adapter::create($this->app, $email, $password, $email, true);
|
$user = \User_Adapter::create($this->app, $email, $password, $email, true);
|
||||||
|
$this->app['authentication']->openAccount($user);
|
||||||
$this->app['session']->set('usr_id', $user->get_id());
|
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace Alchemy\Tests\Phrasea\Authentication;
|
|||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
use Alchemy\Phrasea\Authentication\Authenticator;
|
use Alchemy\Phrasea\Authentication\Authenticator;
|
||||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||||
|
use Entities\Session;
|
||||||
|
|
||||||
class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
|
class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
|
||||||
{
|
{
|
||||||
@@ -33,11 +34,17 @@ class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
|
|||||||
|
|
||||||
$app['browser'] = $browser = $this->getBrowserMock();
|
$app['browser'] = $browser = $this->getBrowserMock();
|
||||||
$app['session'] = $session = $this->getSessionMock();
|
$app['session'] = $session = $this->getSessionMock();
|
||||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
|
||||||
|
$sessionEntity = new Session();
|
||||||
|
$sessionEntity->setUsrId($user->get_id());
|
||||||
|
$sessionEntity->setUserAgent('');
|
||||||
|
$app['EM']->persist($sessionEntity);
|
||||||
|
$app['EM']->flush();
|
||||||
|
|
||||||
$session->set('usr_id', $user->get_id());
|
$session->set('usr_id', $user->get_id());
|
||||||
|
$session->set('session_id', $sessionEntity->getId());
|
||||||
|
|
||||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
$authenticator = new Authenticator($app, $browser, $session, $app['EM']);
|
||||||
$this->assertEquals($user, $authenticator->getUser());
|
$this->assertEquals($user, $authenticator->getUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,8 +76,7 @@ class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
|
|||||||
public function testOpenAccount()
|
public function testOpenAccount()
|
||||||
{
|
{
|
||||||
$app = new Application();
|
$app = new Application();
|
||||||
|
$capturedSession = null;
|
||||||
$sessionId = 2442;
|
|
||||||
|
|
||||||
$app['browser'] = $browser = $this->getBrowserMock();
|
$app['browser'] = $browser = $this->getBrowserMock();
|
||||||
$app['session'] = $session = $this->getSessionMock();
|
$app['session'] = $session = $this->getSessionMock();
|
||||||
@@ -97,11 +103,8 @@ class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
|
|||||||
$em->expects($this->at(0))
|
$em->expects($this->at(0))
|
||||||
->method('persist')
|
->method('persist')
|
||||||
->with($this->isInstanceOf('Entities\Session'))
|
->with($this->isInstanceOf('Entities\Session'))
|
||||||
->will($this->returnCallback(function ($session) use ($sessionId) {
|
->will($this->returnCallback(function ($session) use (&$capturedSession) {
|
||||||
$ref = new \ReflectionObject($session);
|
$capturedSession = $session;
|
||||||
$prop = $ref->getProperty('id');
|
|
||||||
$prop->setAccessible(true);
|
|
||||||
$prop->setValue($session, $sessionId);
|
|
||||||
}));
|
}));
|
||||||
$em->expects($this->at(1))
|
$em->expects($this->at(1))
|
||||||
->method('flush');
|
->method('flush');
|
||||||
@@ -110,7 +113,7 @@ class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
|
|||||||
$phsession = $authenticator->openAccount($user);
|
$phsession = $authenticator->openAccount($user);
|
||||||
|
|
||||||
$this->assertInstanceOf('Entities\Session', $phsession);
|
$this->assertInstanceOf('Entities\Session', $phsession);
|
||||||
$this->assertEquals($sessionId, $session->get('session_id'));
|
$this->assertEquals($capturedSession, $phsession);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -237,11 +240,17 @@ class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
|
|||||||
|
|
||||||
$app['browser'] = $browser = $this->getBrowserMock();
|
$app['browser'] = $browser = $this->getBrowserMock();
|
||||||
$app['session'] = $session = $this->getSessionMock();
|
$app['session'] = $session = $this->getSessionMock();
|
||||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
|
||||||
|
$sessionEntity = new Session();
|
||||||
|
$sessionEntity->setUsrId($user->get_id());
|
||||||
|
$sessionEntity->setUserAgent('');
|
||||||
|
$app['EM']->persist($sessionEntity);
|
||||||
|
$app['EM']->flush();
|
||||||
|
|
||||||
$session->set('usr_id', $user->get_id());
|
$session->set('usr_id', $user->get_id());
|
||||||
|
$session->set('session_id', $sessionEntity->getId());
|
||||||
|
|
||||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
$authenticator = new Authenticator($app, $browser, $session, $app['EM']);
|
||||||
$this->assertTrue($authenticator->isAuthenticated());
|
$this->assertTrue($authenticator->isAuthenticated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user