diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-10-06 09:19:06 +0200 |
---|---|---|
committer | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-10-06 09:19:06 +0200 |
commit | 16dabc326311f084d671be188c7941bbb3c341c9 (patch) | |
tree | 3210a7688ea2bfa1bff5fd0422b52adf570edcdc /src/Wallabag/CoreBundle/Security/Validator | |
parent | fdef5f460524215d806e244e5546865f4b8e01df (diff) | |
parent | 8263e71192989dc0fd28a41ac22f9c5b32eb11c4 (diff) | |
download | wallabag-16dabc326311f084d671be188c7941bbb3c341c9.tar.gz wallabag-16dabc326311f084d671be188c7941bbb3c341c9.tar.zst wallabag-16dabc326311f084d671be188c7941bbb3c341c9.zip |
Merge pull request #1436 from wallabag/v2-register
Public registration & oAuth2 \o/
Diffstat (limited to 'src/Wallabag/CoreBundle/Security/Validator')
-rw-r--r-- | src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php b/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php deleted file mode 100644 index 52062773..00000000 --- a/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Security\Validator; | ||
4 | |||
5 | use Symfony\Component\Security\Core\User\UserInterface; | ||
6 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
7 | use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; | ||
8 | use Symfony\Component\Validator\Constraint; | ||
9 | use Symfony\Component\Validator\ConstraintValidator; | ||
10 | use Symfony\Component\Validator\Exception\ConstraintDefinitionException; | ||
11 | use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
12 | use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; | ||
13 | |||
14 | /** | ||
15 | * @see Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator | ||
16 | */ | ||
17 | class WallabagUserPasswordValidator extends ConstraintValidator | ||
18 | { | ||
19 | private $securityContext; | ||
20 | private $encoderFactory; | ||
21 | |||
22 | public function __construct(TokenStorageInterface $tokenStorage, EncoderFactoryInterface $encoderFactory) | ||
23 | { | ||
24 | $this->tokenStorage = $tokenStorage; | ||
25 | $this->encoderFactory = $encoderFactory; | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * {@inheritdoc} | ||
30 | */ | ||
31 | public function validate($password, Constraint $constraint) | ||
32 | { | ||
33 | if (!$constraint instanceof UserPassword) { | ||
34 | throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword'); | ||
35 | } | ||
36 | |||
37 | $user = $this->tokenStorage->getToken()->getUser(); | ||
38 | |||
39 | if (!$user instanceof UserInterface) { | ||
40 | throw new ConstraintDefinitionException('The User object must implement the UserInterface interface.'); | ||
41 | } | ||
42 | |||
43 | // give username, it's used to hash the password | ||
44 | $encoder = $this->encoderFactory->getEncoder($user); | ||
45 | $encoder->setUsername($user->getUsername()); | ||
46 | |||
47 | if (!$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) { | ||
48 | $this->context->addViolation($constraint->message); | ||
49 | } | ||
50 | } | ||
51 | } | ||