Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }