Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1.     /**
  2.      * @Route("/change/email", name="user_dashboard_change_email")
  3.      */
  4.     public function changeEmailAction(Request $request)
  5.     {
  6.         $user = $this->getUser();
  7.         if (!is_object($user) || !$user instanceof UserInterface) {
  8.             throw new AccessDeniedException('This user does not have access to this section.');
  9.         }
  10.  
  11.         $formEmail = $this->createForm(EmailFormType::class);
  12.         $formEmail->handleRequest($request);
  13.  
  14.         if ($formEmail->isSubmitted() && $formEmail->isValid()) {
  15.  
  16.             $default = new MessageDigestPasswordEncoder('sha512', true, 5000);
  17.  
  18.             $encoderFactory = new EncoderFactory([
  19.                 User::class => $default
  20.             ]);
  21.  
  22.             $data = $formEmail->getData();
  23.             $encoder = $encoderFactory->getEncoder($user);
  24.             $plainPass = $data['plainPassword'];
  25.             $bool = $encoder->isPasswordValid($user->getPassword(), $plainPass, $user->getSalt());
  26.  
  27.             if ($bool){
  28.                 $this->addFlash(
  29.                     'message','Twój adres email został zmieniony'
  30.                 );
  31.  
  32.                 $user->setEmail($data['email']);
  33.                 $em = $this->getDoctrine()->getManager();
  34.                 $em-> flush();
  35.  
  36.                 return $this->redirectToRoute('user_dashboard_change_pass');
  37.             }
  38.             $this->addFlash(
  39.                 'message','Błędne hasło!'
  40.             );
  41.             return $this->redirectToRoute('user_dashboard_change_pass');
  42.         }
  43.         $this->addFlash(
  44.             'message','Wystąpił błąd.'
  45.         );
  46.         return $this->redirectToRoute('user_dashboard_change_pass');
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement