Example #1
0
 /**
  * 使用单点登录票据获取用户数据
  *
  * 该方法是为了便捷API Client获取资源流程而设计的富接口
  *
  * @param string $ticket  单点登录票据
  * @param array  $needs   需要得到的资源
  * @throws ResourceException
  */
 public function getUserAction($ticket, $needs)
 {
     $online = Online::findPrimary($ticket);
     if ($online) {
         $user = Users::findPrimary($online->UID);
         if ($user) {
             $data = array('UID' => $user->UID, 'username' => $user->username);
             $meta = new UserMetaController();
             foreach ($needs as $need) {
                 try {
                     switch ($need) {
                         case 'portrait':
                             $upload = new UploadController();
                             $upload->getUserPortraitAddressAction($user->UID);
                             $data = array_merge($data, (array) $upload->resource);
                             break;
                         default:
                             $meta->getUserMetaAction($user->UID, $need);
                             $data[$need] = $meta->resource->meta_value;
                     }
                 } catch (ResourceException $e) {
                     if ($e->getCode() == 404) {
                         $data[$need] = '';
                     } else {
                         throw $e;
                     }
                 }
             }
             $this->response(200, 'OK', $data);
         } else {
             throw new ResourceException('Not Found', 404);
         }
     } else {
         throw new ResourceException('Not Found', 404);
     }
 }
Example #2
0
 /**
  * 删除用户在线状态
  *
  * @param string $ticket  Ticket票据
  * @throws ResourceException
  */
 public function deleteUserAction($ticket)
 {
     $online = Online::findPrimary($ticket);
     if (!$online) {
         throw new ResourceException('Not Found', 404);
     }
     if ($online->delete()) {
         $this->response(204, 'No Content');
     } else {
         throw new ResourceException('Internal Server Error', 500);
     }
 }