public function testThatALogicExceptionIsThrownIfNoLoginProvided()
 {
     $mail = MailRequestPasswordUpdate::create($this->getApplication(), $this->getReceiverMock(), $this->getEmitterMock(), $this->getMessage(), $this->getUrl(), $this->getExpiration());
     try {
         $mail->getMessage();
         $this->fail('Should have raised an exception');
     } catch (LogicException $e) {
     }
 }
Пример #2
0
 /**
  * Submit the new password
  *
  * @param  Application      $app     A Silex application where the controller is mounted on
  * @param  Request          $request The current request
  * @return RedirectResponse
  */
 public function forgotPassword(PhraseaApplication $app, Request $request)
 {
     $form = $app->form(new PhraseaForgotPasswordForm());
     try {
         if ('POST' === $request->getMethod()) {
             $form->bind($request);
             if ($form->isValid()) {
                 $data = $form->getData();
                 if (null === ($user = $app['manipulator.user']->getRepository()->findByEmail($data['email']))) {
                     throw new FormProcessingException(_('phraseanet::erreur: Le compte n\'a pas ete trouve'));
                 }
                 try {
                     $receiver = Receiver::fromUser($user);
                 } catch (InvalidArgumentException $e) {
                     throw new FormProcessingException($app->trans('Invalid email address'));
                 }
                 $token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->getId(), new \DateTime('+1 day'));
                 if (!$token) {
                     return $app->abort(500, 'Unable to generate a token');
                 }
                 $url = $app->url('login_renew_password', ['token' => $token], true);
                 $mail = MailRequestPasswordUpdate::create($app, $receiver);
                 $mail->setLogin($user->getLogin());
                 $mail->setButtonUrl($url);
                 $app['notification.deliverer']->deliver($mail);
                 $app->addFlash('info', $app->trans('phraseanet:: Un email vient de vous etre envoye'));
                 return $app->redirectPath('login_forgot_password');
             }
         }
     } catch (FormProcessingException $e) {
         $app->addFlash('error', $e->getMessage());
     }
     return $app['twig']->render('login/forgot-password.html.twig', array_merge(self::getDefaultTemplateVariables($app), ['form' => $form->createView()]));
 }
Пример #3
0
 /**
  * @param User $user
  * @param bool $notifyUser
  * @return string
  */
 private function requestPasswordResetTokenByUser(User $user, $notifyUser = true)
 {
     $receiver = Receiver::fromUser($user);
     $token = $this->tokenManipulator->createResetPasswordToken($user);
     if ($notifyUser) {
         $url = $this->urlGenerator->generate('login_renew_password', ['token' => $token->getValue()], true);
         $mail = MailRequestPasswordUpdate::create($this->application, $receiver);
         $mail->setLogin($user->getLogin());
         $mail->setButtonUrl($url);
         $mail->setExpiration(new \DateTime('+1 day'));
         $this->mailer->deliver($mail);
     }
     return $token->getValue();
 }