/** * Sends the password-reset-token of a user to an email-adress. * * @param UserInterface $user * @param string $from From-Email-Address * @param string $to To-Email-Address * * @throws NoTokenFoundException * @throws TokenEmailsLimitReachedException */ private function sendTokenEmail(UserInterface $user, $from, $to) { if ($user->getPasswordResetToken() === null) { throw new NoTokenFoundException($user); } if ($user->getPasswordResetTokenEmailsSent() === self::MAX_NUMBER_EMAILS) { throw new TokenEmailsLimitReachedException(self::MAX_NUMBER_EMAILS, $user); } $mailer = $this->get('mailer'); $em = $this->getDoctrine()->getManager(); $message = $mailer->createMessage()->setSubject($this->getSubject())->setFrom($from)->setTo($to)->setBody($this->getMessage($user)); $mailer->send($message); $user->setPasswordResetTokenEmailsSent($user->getPasswordResetTokenEmailsSent() + 1); $em->persist($user); $em->flush(); }
/** * Sends the password-reset-token of a user to an email-adress. * * @param UserInterface $user * @param string $from From-Email-Address * @param string $to To-Email-Address * * @throws NoTokenFoundException * @throws TokenEmailsLimitReachedException */ private function sendTokenEmail(UserInterface $user, $from, $to) { if ($user->getPasswordResetToken() === null) { throw new NoTokenFoundException($user); } if ($user->getPasswordResetTokenEmailsSent() === self::MAX_NUMBER_EMAILS) { throw new TokenEmailsLimitReachedException(self::MAX_NUMBER_EMAILS, $user); } $mailer = $this->get('mailer'); $translator = $this->get('translator'); $em = $this->getDoctrine()->getManager(); $message = $mailer->createMessage()->setSubject($translator->trans(static::$emailSubjectKey, [], static::$translationDomain))->setFrom($from)->setTo($to)->setBody($translator->trans(static::$emailMessageKey, [], static::$translationDomain) . PHP_EOL . $this->generateUrl('sulu_admin.reset', ['token' => $user->getPasswordResetToken()], true)); $mailer->send($message); $user->setPasswordResetTokenEmailsSent($user->getPasswordResetTokenEmailsSent() + 1); $em->persist($user); $em->flush(); }