/**
  * Reset Email
  *
  * @param  Request $request
  * @return RedirectResponse
  */
 public function resetEmail(Request $request)
 {
     if (null === ($password = $request->request->get('form_password')) || null === ($email = $request->request->get('form_email')) || null === ($emailConfirm = $request->request->get('form_email_confirm'))) {
         throw new BadRequestHttpException($this->app->trans('Could not perform request, please contact an administrator.'));
     }
     $user = $this->getAuthenticatedUser();
     if (!$this->getPasswordEncoder()->isPasswordValid($user->getPassword(), $password, $user->getNonce())) {
         $this->app->addFlash('error', $this->app->trans('admin::compte-utilisateur:ftp: Le mot de passe est errone'));
         return $this->app->redirectPath('account_reset_email');
     }
     if (!\Swift_Validate::email($email)) {
         $this->app->addFlash('error', $this->app->trans('forms::l\'email semble invalide'));
         return $this->app->redirectPath('account_reset_email');
     }
     if ($email !== $emailConfirm) {
         $this->app->addFlash('error', $this->app->trans('forms::les emails ne correspondent pas'));
         return $this->app->redirectPath('account_reset_email');
     }
     $token = $this->getTokenManipulator()->createResetEmailToken($user, $email);
     $url = $this->app->url('account_reset_email', ['token' => $token->getValue()]);
     try {
         $receiver = Receiver::fromUser($user);
     } catch (InvalidArgumentException $e) {
         $this->app->addFlash('error', $this->app->trans('phraseanet::erreur: echec du serveur de mail'));
         return $this->app->redirectPath('account_reset_email');
     }
     $mail = MailRequestEmailUpdate::create($this->app, $receiver, null);
     $mail->setButtonUrl($url);
     $mail->setExpiration($token->getExpiration());
     $this->deliver($mail);
     $this->app->addFlash('info', $this->app->trans('admin::compte-utilisateur un email de confirmation vient de vous etre envoye. Veuillez suivre les instructions contenue pour continuer'));
     return $this->app->redirectPath('account');
 }
Exemple #2
0
 /**
  * Reset Email
  *
  * @param  Application      $app
  * @param  Request          $request
  * @return RedirectResponse
  */
 public function resetEmail(PhraseaApplication $app, Request $request)
 {
     if (null === ($password = $request->request->get('form_password')) || null === ($email = $request->request->get('form_email')) || null === ($emailConfirm = $request->request->get('form_email_confirm'))) {
         $app->abort(400, $app->trans('Could not perform request, please contact an administrator.'));
     }
     $user = $app['authentication']->getUser();
     if (!$app['auth.password-encoder']->isPasswordValid($user->getPassword(), $password, $user->getNonce())) {
         $app->addFlash('error', $app->trans('admin::compte-utilisateur:ftp: Le mot de passe est errone'));
         return $app->redirectPath('account_reset_email');
     }
     if (!\Swift_Validate::email($email)) {
         $app->addFlash('error', $app->trans('forms::l\'email semble invalide'));
         return $app->redirectPath('account_reset_email');
     }
     if ($email !== $emailConfirm) {
         $app->addFlash('error', $app->trans('forms::les emails ne correspondent pas'));
         return $app->redirectPath('account_reset_email');
     }
     $date = new \DateTime('1 day');
     $token = $app['tokens']->getUrlToken(\random::TYPE_EMAIL, $app['authentication']->getUser()->getId(), $date, $app['authentication']->getUser()->getEmail());
     $url = $app->url('account_reset_email', ['token' => $token]);
     try {
         $receiver = Receiver::fromUser($app['authentication']->getUser());
     } catch (InvalidArgumentException $e) {
         $app->addFlash('error', $app->trans('phraseanet::erreur: echec du serveur de mail'));
         return $app->redirectPath('account_reset_email');
     }
     $mail = MailRequestEmailUpdate::create($app, $receiver, null);
     $mail->setButtonUrl($url);
     $mail->setExpiration($date);
     $app['notification.deliverer']->deliver($mail);
     $app->addFlash('info', $app->trans('admin::compte-utilisateur un email de confirmation vient de vous etre envoye. Veuillez suivre les instructions contenue pour continuer'));
     return $app->redirectPath('account');
 }
 public function getMail()
 {
     return MailRequestEmailUpdate::create($this->getApplication(), $this->getReceiverMock(), $this->getEmitterMock(), $this->getMessage(), $this->getUrl(), $this->getExpiration());
 }