From d9085c63e35bb708f560722fff5f4f5ad322c27b Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 17 Feb 2015 21:03:23 +0100 Subject: Handle password change --- .../Validator/WallabagUserPasswordValidator.php | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php (limited to 'src/Wallabag/CoreBundle/Security/Validator') diff --git a/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php b/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php new file mode 100644 index 00000000..5586f976 --- /dev/null +++ b/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php @@ -0,0 +1,48 @@ +securityContext = $securityContext; + $this->encoderFactory = $encoderFactory; + } + + /** + * {@inheritdoc} + */ + public function validate($password, Constraint $constraint) + { + if (!$constraint instanceof UserPassword) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword'); + } + + $user = $this->securityContext->getToken()->getUser(); + + if (!$user instanceof UserInterface) { + throw new ConstraintDefinitionException('The User object must implement the UserInterface interface.'); + } + + // give username, it's used to hash the password + $encoder = $this->encoderFactory->getEncoder($user); + $encoder->setUsername($user->getUsername()); + + if (!$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) { + $this->context->addViolation($constraint->message); + } + } +} -- cgit v1.2.3