Fixed logging in from multiple computers
This commit is contained in:
parent
6c76f016e7
commit
3268618f26
4 changed files with 44 additions and 11 deletions
1
TODO
1
TODO
|
@ -107,7 +107,6 @@ refactors:
|
|||
- reduce dependencies
|
||||
|
||||
miscellaneous:
|
||||
- use 1 token for logins, so that session isn't killed
|
||||
- endless pager should include information about page number
|
||||
- add customizable favicon
|
||||
- add customizable logo
|
||||
|
|
|
@ -16,6 +16,18 @@ class TokenDao extends AbstractDao
|
|||
return $this->findOneBy('name', $tokenName);
|
||||
}
|
||||
|
||||
public function findByAdditionalDataAndPurpose($additionalData, $purpose)
|
||||
{
|
||||
$query = $this->fpdo->from($this->tableName)
|
||||
->where('additionalData', $additionalData)
|
||||
->where('purpose', $purpose);
|
||||
$arrayEntities = iterator_to_array($query);
|
||||
if (!$arrayEntities or !count($arrayEntities))
|
||||
return null;
|
||||
$arrayEntity = array_shift($arrayEntities);
|
||||
return $this->entityConverter->toEntity($arrayEntity);
|
||||
}
|
||||
|
||||
public function deleteByName($tokenName)
|
||||
{
|
||||
return $this->deleteBy('name', $tokenName);
|
||||
|
|
|
@ -48,12 +48,17 @@ class TokenService
|
|||
{
|
||||
$transactionFunc = function() use ($additionalData, $tokenPurpose)
|
||||
{
|
||||
$token = new \Szurubooru\Entities\Token();
|
||||
$token->setName(sha1(date('r') . uniqid() . microtime(true)));
|
||||
$token->setAdditionalData($additionalData);
|
||||
$token->setPurpose($tokenPurpose);
|
||||
$this->invalidateByAdditionalData($additionalData);
|
||||
$this->tokenDao->save($token);
|
||||
$token = $this->tokenDao->findByAdditionalDataAndPurpose($additionalData, $tokenPurpose);
|
||||
|
||||
if (!$token)
|
||||
{
|
||||
$token = new \Szurubooru\Entities\Token();
|
||||
$token->setName(sha1(date('r') . uniqid() . microtime(true)));
|
||||
$token->setAdditionalData($additionalData);
|
||||
$token->setPurpose($tokenPurpose);
|
||||
$this->tokenDao->save($token);
|
||||
}
|
||||
|
||||
return $token;
|
||||
};
|
||||
return $this->transactionManager->commit($transactionFunc);
|
||||
|
|
|
@ -5,12 +5,11 @@ final class TokenDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|||
{
|
||||
public function testRetrievingByValidName()
|
||||
{
|
||||
$tokenDao = new \Szurubooru\Dao\TokenDao($this->databaseConnection);
|
||||
|
||||
$token = new \Szurubooru\Entities\Token();
|
||||
$token->setName('test');
|
||||
$token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN);
|
||||
|
||||
$tokenDao = $this->getTokenDao();
|
||||
$tokenDao->save($token);
|
||||
$expected = $token;
|
||||
$actual = $tokenDao->findByName($token->getName());
|
||||
|
@ -20,10 +19,28 @@ final class TokenDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|||
|
||||
public function testRetrievingByInvalidName()
|
||||
{
|
||||
$tokenDao = new \Szurubooru\Dao\TokenDao($this->databaseConnection);
|
||||
|
||||
$tokenDao = $this->getTokenDao();
|
||||
$actual = $tokenDao->findByName('rubbish');
|
||||
|
||||
$this->assertNull($actual);
|
||||
}
|
||||
|
||||
public function testRetrievingByAdditionalDataAndPurpose()
|
||||
{
|
||||
$token = new \Szurubooru\Entities\Token();
|
||||
$token->setName('test');
|
||||
$token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN);
|
||||
|
||||
$tokenDao = $this->getTokenDao();
|
||||
$tokenDao->save($token);
|
||||
$expected = $token;
|
||||
|
||||
$this->assertEntitiesEqual($expected, $tokenDao->findByAdditionalDataAndPurpose(null, \Szurubooru\Entities\Token::PURPOSE_LOGIN));
|
||||
$this->assertNull($tokenDao->findByAdditionalDataAndPurpose(null, \Szurubooru\Entities\Token::PURPOSE_ACTIVATE));
|
||||
}
|
||||
|
||||
private function getTokenDao()
|
||||
{
|
||||
return new \Szurubooru\Dao\TokenDao($this->databaseConnection);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue