public function forgotPasswordAction() { $form = new ForgotPasswordForm(); if ($this->request->isPost()) { if ($form->isValid($this->request->getPost()) == false) { foreach ($form->getMessages() as $message) { $this->flash->error($message); } } else { $user = Users::findFirstByEmail($this->request->getPost('email')); if (!$user) { $this->flash->success('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($message); } } } } } $this->view->form = $form; }
public function getUser() { $identity = $this->session->get('auth-identity'); if (isset($identity['id'])) { $user = Users::findFirstById($identity['id']); if ($user == false) { throw new Exception('The user does not exist'); } return $user; } return false; }
public function deleteAction() { $response = new Response(); $response->setHeader('Content-Type', 'application/json'); if ($this->request->isPost()) { $id = $this->request->getPost('id', 'int'); $user = Users::findFirstById($id); if (!$user) { $response->setJsonContent(array('status' => 'error', 'messages' => '没有对应的用户')); } if (!$user->delete()) { $response->setJsonContent(array('status' => 'error', 'messages' => '删除时发生错误')); } else { $response->setJsonContent(array('status' => 'success', 'messages' => '')); } } return $response; }