/** * Send an e-mail to users allowing him/her to reset his/her password */ public function afterCreate() { $user = \Nucleo\Models\Users::findFirst(['userName = ?0', 'bind' => [$this->usersName]]); $mail = $this->getDI()->getMail()->send([$user->email => $user->name], 'Redefinição de senha da Intranet do Grupo MPE', 'reset', ['resetUrl' => 'reset-password/' . $this->code . '/' . $user->email, 'nameUser' => $user->name]); if ($mail != true) { throw new \Exception($msg); } }
/** * * @return type * @throws Exception */ public function resetPasswordAction() { try { $code = $this->dispatcher->getParam('code'); $resetPassword = ResetPasswords::findFirstByCode($code); if (!$resetPassword) { throw new Exception('Não foi possível encontrar o código.'); } if ($resetPassword->reset != 'N') { throw new Exception('Código expirado.'); } $resetPassword->reset = 'Y'; if (!$resetPassword->save()) { $msg = ''; foreach ($resetPassword->getMessages() as $message) { $msg .= $message . '<br>'; } throw new Exception($msg); } $user = Users::findFirst(['userName = ?0', 'bind' => [$resetPassword->usersName]]); $this->auth->authUserById($user->id); $this->flash->notice('Por favor, redefina sua senha.'); return $this->response->redirect('change-password'); } catch (\Exception $e) { $this->flash->error($e->getMessage()); } return $this->response->redirect('login'); }