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
|
- reduce dependencies
|
||||||
|
|
||||||
miscellaneous:
|
miscellaneous:
|
||||||
- use 1 token for logins, so that session isn't killed
|
|
||||||
- endless pager should include information about page number
|
- endless pager should include information about page number
|
||||||
- add customizable favicon
|
- add customizable favicon
|
||||||
- add customizable logo
|
- add customizable logo
|
||||||
|
|
|
@ -16,6 +16,18 @@ class TokenDao extends AbstractDao
|
||||||
return $this->findOneBy('name', $tokenName);
|
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)
|
public function deleteByName($tokenName)
|
||||||
{
|
{
|
||||||
return $this->deleteBy('name', $tokenName);
|
return $this->deleteBy('name', $tokenName);
|
||||||
|
|
|
@ -48,12 +48,17 @@ class TokenService
|
||||||
{
|
{
|
||||||
$transactionFunc = function() use ($additionalData, $tokenPurpose)
|
$transactionFunc = function() use ($additionalData, $tokenPurpose)
|
||||||
{
|
{
|
||||||
$token = new \Szurubooru\Entities\Token();
|
$token = $this->tokenDao->findByAdditionalDataAndPurpose($additionalData, $tokenPurpose);
|
||||||
$token->setName(sha1(date('r') . uniqid() . microtime(true)));
|
|
||||||
$token->setAdditionalData($additionalData);
|
if (!$token)
|
||||||
$token->setPurpose($tokenPurpose);
|
{
|
||||||
$this->invalidateByAdditionalData($additionalData);
|
$token = new \Szurubooru\Entities\Token();
|
||||||
$this->tokenDao->save($token);
|
$token->setName(sha1(date('r') . uniqid() . microtime(true)));
|
||||||
|
$token->setAdditionalData($additionalData);
|
||||||
|
$token->setPurpose($tokenPurpose);
|
||||||
|
$this->tokenDao->save($token);
|
||||||
|
}
|
||||||
|
|
||||||
return $token;
|
return $token;
|
||||||
};
|
};
|
||||||
return $this->transactionManager->commit($transactionFunc);
|
return $this->transactionManager->commit($transactionFunc);
|
||||||
|
|
|
@ -5,12 +5,11 @@ final class TokenDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
public function testRetrievingByValidName()
|
public function testRetrievingByValidName()
|
||||||
{
|
{
|
||||||
$tokenDao = new \Szurubooru\Dao\TokenDao($this->databaseConnection);
|
|
||||||
|
|
||||||
$token = new \Szurubooru\Entities\Token();
|
$token = new \Szurubooru\Entities\Token();
|
||||||
$token->setName('test');
|
$token->setName('test');
|
||||||
$token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN);
|
$token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN);
|
||||||
|
|
||||||
|
$tokenDao = $this->getTokenDao();
|
||||||
$tokenDao->save($token);
|
$tokenDao->save($token);
|
||||||
$expected = $token;
|
$expected = $token;
|
||||||
$actual = $tokenDao->findByName($token->getName());
|
$actual = $tokenDao->findByName($token->getName());
|
||||||
|
@ -20,10 +19,28 @@ final class TokenDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
|
|
||||||
public function testRetrievingByInvalidName()
|
public function testRetrievingByInvalidName()
|
||||||
{
|
{
|
||||||
$tokenDao = new \Szurubooru\Dao\TokenDao($this->databaseConnection);
|
$tokenDao = $this->getTokenDao();
|
||||||
|
|
||||||
$actual = $tokenDao->findByName('rubbish');
|
$actual = $tokenDao->findByName('rubbish');
|
||||||
|
|
||||||
$this->assertNull($actual);
|
$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