Skip to content

Commit

Permalink
Merge pull request #181 from dschoenbauer/develop
Browse files Browse the repository at this point in the history
1.5.5
  • Loading branch information
dschoenbauer committed Sep 24, 2018
2 parents a6bb9a0 + 567270a commit 2bb7e57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Orm/Events/Filter/PasswordValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ public function validateUser($data, HasPasswordInterface $passwordInfo)
return false;
}
$meta = $this->getPasswordMetaData($data[$passwordInfo->getUserNameField()], $passwordInfo);
return $passwordInfo->getPasswordMaskStrategy()->validate($data[$passwordInfo->getPasswordField()], $meta->hash) ? $meta->id : false;
return $passwordInfo
->getPasswordMaskStrategy()
->validate($data[$passwordInfo->getPasswordField()], $meta->hash) ? $meta->id : false;
}

public function getPasswordMetaData($userName, HasPasswordInterface $passwordInfo)
{
return $this->getSelect()
->setTable($passwordInfo->getTable())
->setFields([$passwordInfo->getPasswordField()])
->setFields([$passwordInfo->getPasswordField() . ' as hash', $passwordInfo->getIdField() . ' as id'])
->setWhere(new ArrayWhere([$passwordInfo->getUserNameField() => $userName]))
->setFetchFlat()
->setFetchStyle(\PDO::FETCH_OBJ)
->setDefaultValue($this->getNullReturn())
->execute($this->getAdapter());
}

public function getNullReturn($id = null, $hash = null)
{
$obj = new stdClass();
Expand Down
4 changes: 3 additions & 1 deletion tests/src/Orm/Events/Filter/PasswordValidateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public function testGetPasswordMetaData()
{
$userName = "test";
$table = 'table';
$idField = 'idField';
$passwordField = 'passwordField';
$userNameField = 'userNameField';

Expand All @@ -205,14 +206,15 @@ public function testGetPasswordMetaData()

$passwordInfo = $this->getMockBuilder(HasPasswordInterface::class)->getMock();
$passwordInfo->expects($this->any())->method('getTable')->willReturn($table);
$passwordInfo->expects($this->any())->method('getIdField')->willReturn($idField);
$passwordInfo->expects($this->any())->method('getPasswordField')->willReturn($passwordField);
$passwordInfo->expects($this->any())->method('getUserNameField')->willReturn($userNameField);

$select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()
//->setMethods(['setTable','setFields','setWhere','setFetchFlat','setFetchStyle','setDefaultValue','execute'])
->getMock();
$select->expects($this->atLeast(1))->method('setTable')->with($table)->willReturnSelf();
$select->expects($this->atLeast(1))->method('setFields')->with([$passwordField])->willReturnSelf();
$select->expects($this->atLeast(1))->method('setFields')->with([$passwordField . ' as hash', $idField . ' as id'])->willReturnSelf();
$select->expects($this->atLeast(1))->method('setWhere')->with($this->isInstanceOf(ArrayWhere::class))->willReturnSelf(); //Needs to be better
$select->expects($this->atLeast(1))->method('setFetchFlat')->willReturnSelf();
$select->expects($this->atLeast(1))->method('setFetchStyle')->with(\PDO::FETCH_OBJ)->willReturnSelf();
Expand Down

0 comments on commit 2bb7e57

Please sign in to comment.