In Vokuro, on resetting a password, an email is generated using
$this->getDI()
->getMail()
->send([
$this->user->email => $this->user->name,
], "Reset your password", 'reset', [
'resetUrl' => '/reset-password/' . $this->code . '/' . $this->user->email,
]);
in afterCreate method.
I am tring to catch exception by changing this like:
try{
$this->getDI()
->getMail()
->send([
$this->user->email => $this->user->name,
], "Reset your password", 'reset', [
'resetUrl' => '/reset-password/' . $this->code . '/' . $this->user->email,
]);
} catch (MailException $e) {
$this->getDI()->getFlash()->error($e->getMessage());
}
Am I in the right direction?
[UPDATE]
On using \Swift_TransportException
, the view is not rendering further and i get blank page. I changed back the above code to default and then in my controller action added try - catch like this:
$form = new ForgotPasswordForm();
try{
if ($this->request->isPost()) {
// Send emails only is config value is set to true
if ($this->getDI()->get('config')->useMail) {
if ($form->isValid($this->request->getPost()) == false) {
foreach ($form->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$user = Users::findFirstByEmail($this->request->getPost('email'));
if (!$user) {
$this->flash->warning('There is no account associated to this email');
} else {
$resetPassword = new ResetPasswords();
$resetPassword->usersId = $user->id;
if ($resetPassword->save()) {
$this->flash->success('Success! Please check your messages for an email reset password');
} else {
foreach ($resetPassword->getMessages() as $message) {
$this->flash->error((string) $message);
}
}
}
}
} else {
$this->flash->warning(
'Service not available at the moment. Please try again later.'
);
}
}
} catch (\Swift_TransportException $Ste) {
$this->flash->error("Error.");
}
$this->view->setVar('form', $form);