/** * Callback method, that is called once form is successfully submitted, without validation errors. * * @param Form $form * @param Nette\Utils\ArrayHash $values */ public function formSucceeded(Form $form, $values) { if (!($user = $this->userRepository->findOneBy(['email' => $values->email]))) { $form['email']->addError("User with given email doesn't exist"); return; } // this is not a very secure way of getting new password // but it's the same way the symfony app is doing it... $newPassword = $user->generateRandomPassword(); $this->em->flush(); try { $message = new Nette\Mail\Message(); $message->setSubject('Notejam password'); $message->setFrom('*****@*****.**'); $message->addTo($user->getEmail()); // !!! Never send passwords through email !!! // This is only for demonstration purposes of Notejam. // Ideally, you can create a unique link where user can change his password // himself for limited amount of time, and then send the link. $message->setBody("Your new password is {$newPassword}"); $this->mailer->send($message); } catch (Nette\Mail\SendException $e) { Debugger::log($e, 'email'); $form->addError('Could not send email with new password'); } $this->onSuccess($this); }