Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Route("/change/email", name="user_dashboard_change_email")
- */
- public function changeEmailAction(Request $request)
- {
- $user = $this->getUser();
- if (!is_object($user) || !$user instanceof UserInterface) {
- throw new AccessDeniedException('This user does not have access to this section.');
- }
- $formEmail = $this->createForm(EmailFormType::class);
- $formEmail->handleRequest($request);
- if ($formEmail->isSubmitted() && $formEmail->isValid()) {
- $default = new MessageDigestPasswordEncoder('sha512', true, 5000);
- $encoderFactory = new EncoderFactory([
- User::class => $default
- ]);
- $data = $formEmail->getData();
- $encoder = $encoderFactory->getEncoder($user);
- $plainPass = $data['plainPassword'];
- $bool = $encoder->isPasswordValid($user->getPassword(), $plainPass, $user->getSalt());
- if ($bool){
- $this->addFlash(
- 'message','Twój adres email został zmieniony'
- );
- $user->setEmail($data['email']);
- $em = $this->getDoctrine()->getManager();
- $em-> flush();
- return $this->redirectToRoute('user_dashboard_change_pass');
- }
- $this->addFlash(
- 'message','Błędne hasło!'
- );
- return $this->redirectToRoute('user_dashboard_change_pass');
- }
- $this->addFlash(
- 'message','Wystąpił błąd.'
- );
- return $this->redirectToRoute('user_dashboard_change_pass');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement