Guest User

Untitled

a guest
May 19th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
  2. {
  3. $username = $request->request->get('_username');
  4. $password = $request->request->get('_password');
  5.  
  6. $user = $this->doctrine->getRepository('AppBundle:User')->findOneByUsername($username);
  7.  
  8. if ($user instanceof User && $user->getFromWordpress() == true) {
  9.  
  10. //The class use by WordPress to check / encode passwords
  11. $hasher = new PasswordHash(8, TRUE);
  12.  
  13. //User provide the right password
  14. if ($hasher->CheckPassword($password, $user->getWordpressPassword())){
  15.  
  16. //Programmatically authenticate the user
  17. $token = new UsernamePasswordToken($user, $user->getPassword(), "main", $user->getRoles());
  18. $this->tokenStorage->setToken($token);
  19. $event = new InteractiveLoginEvent($request, $token);
  20. $this->eventDispacher->dispatch("security.interactive_login", $event);
  21.  
  22. //Set the password with the Symfony2 encoder
  23. $encoder = $this->encoderFactory->getEncoder($user);
  24. $password = $encoder->encodePassword($password, $user->getSalt());
  25. $user->setPassword($password);
  26. $user->setFromWordpress(false);
  27. $this->doctrine->getManager()->persist($user);
  28. $this->doctrine->getManager()->flush();
  29.  
  30. //Finnaly send login ok response
  31. return $this->onAuthenticationSuccess($request, $token);
  32. }
  33. }
  34.  
  35. //Login failed code ...
  36. //.....
  37. }
Add Comment
Please, Sign In to add comment