/** * Shows the forgot password form */ public function forgotPasswordAction() { $form = new ForgotPasswordForm(); if ($this->request->isPost()) { if ($form->isValid($this->request->getPost()) === false) { foreach ($form->getMessages() as $message) { $this->flashSession->error($message); } } else { $user = Users::findFirstByEmail($this->request->getPost('email')); if (!$user) { $this->flashSession->error('There is no account associated with this email'); } else { $resetPassword = new ResetPasswords(); $resetPassword->usersId = $user->id; if ($resetPassword->save()) { $this->flashSession->success('Success! You have been sent an email with instructions on how to reset your password.'); return $this->redirect('session', 'login'); } else { foreach ($resetPassword->getMessages() as $message) { $this->flashSession->error($message); } } } } } $this->view->setVar('form', $form); }