Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
- {
- $username = $request->request->get('_username');
- $password = $request->request->get('_password');
- $user = $this->doctrine->getRepository('AppBundle:User')->findOneByUsername($username);
- if ($user instanceof User && $user->getFromWordpress() == true) {
- //The class use by WordPress to check / encode passwords
- $hasher = new PasswordHash(8, TRUE);
- //User provide the right password
- if ($hasher->CheckPassword($password, $user->getWordpressPassword())){
- //Programmatically authenticate the user
- $token = new UsernamePasswordToken($user, $user->getPassword(), "main", $user->getRoles());
- $this->tokenStorage->setToken($token);
- $event = new InteractiveLoginEvent($request, $token);
- $this->eventDispacher->dispatch("security.interactive_login", $event);
- //Set the password with the Symfony2 encoder
- $encoder = $this->encoderFactory->getEncoder($user);
- $password = $encoder->encodePassword($password, $user->getSalt());
- $user->setPassword($password);
- $user->setFromWordpress(false);
- $this->doctrine->getManager()->persist($user);
- $this->doctrine->getManager()->flush();
- //Finnaly send login ok response
- return $this->onAuthenticationSuccess($request, $token);
- }
- }
- //Login failed code ...
- //.....
- }
Add Comment
Please, Sign In to add comment