mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Fix PasswordToken constraint
This commit is contained in:
@@ -31,11 +31,11 @@ class PasswordToken extends Constraint
|
|||||||
public function isValid($token)
|
public function isValid($token)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$datas = $this->random->helloToken($this->app, $token);
|
$data = $this->random->helloToken($token);
|
||||||
} catch (\Exception_NotFound $e) {
|
} catch (\Exception_NotFound $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \random::TYPE_PASSWORD === $datas['type'];
|
return \random::TYPE_PASSWORD === $data['type'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ class PasswordTokenValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
public function validate($value, Constraint $constraint)
|
public function validate($value, Constraint $constraint)
|
||||||
{
|
{
|
||||||
if ($constraint->isValid($value)) {
|
if (!$constraint->isValid($value)) {
|
||||||
$this->context->addViolation('The token provided is not valid anymore');
|
$this->context->addViolation('The token provided is not valid anymore');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ class PasswordTokenTest extends \PhraseanetPHPUnitAbstract
|
|||||||
$random
|
$random
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('helloToken')
|
->method('helloToken')
|
||||||
->with(self::$DI['app'], $token)
|
->with($token)
|
||||||
->will($this->throwException(new \Exception_NotFound('Token not found')));
|
->will($this->throwException(new \Exception_NotFound('Token not found')));
|
||||||
|
|
||||||
$constraint = new PasswordToken(self::$DI['app'], $random);
|
$constraint = new PasswordToken(self::$DI['app'], $random);
|
||||||
@@ -39,7 +39,7 @@ class PasswordTokenTest extends \PhraseanetPHPUnitAbstract
|
|||||||
$random
|
$random
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('helloToken')
|
->method('helloToken')
|
||||||
->with(self::$DI['app'], $token)
|
->with($token)
|
||||||
->will($this->returnValue(array('usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD)));
|
->will($this->returnValue(array('usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD)));
|
||||||
|
|
||||||
$constraint = new PasswordToken(self::$DI['app'], $random);
|
$constraint = new PasswordToken(self::$DI['app'], $random);
|
||||||
|
@@ -13,10 +13,10 @@ class PasswordTokenValidatorTest extends \PhraseanetPHPUnitAbstract
|
|||||||
{
|
{
|
||||||
$context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
|
$context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
|
||||||
$builder = $context
|
$builder = $context
|
||||||
->expects($this->exactly($isValid ? 1 : 0))
|
->expects($this->exactly($isValid ? 0 : 1))
|
||||||
->method('addViolation');
|
->method('addViolation');
|
||||||
|
|
||||||
if ($isValid) {
|
if (!$isValid) {
|
||||||
$builder->with($this->isType('string'));
|
$builder->with($this->isType('string'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user