Exemple #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);
     }
 }
 /**
  * 检查用户昵称是否使用
  *
  * @param string $nickname 被检测的昵称
  */
 public function getCheckNicknameAction($nickname)
 {
     $meta = new UserMetaController();
     $data = array('name' => 'nickname', 'result' => $meta->getMetaValueExists('nickname', $nickname));
     $this->responseJson(200, 'OK', $data)->send();
 }
Exemple #3
0
 /**
  * 获取用户头像地址
  *
  * @param integer $uid  用户ID
  * @throws ResourceException
  */
 public function getUserPortraitAddressAction($uid)
 {
     $portraitAddresses = array('portrait_50' => '', 'portrait_140' => '', 'portrait_260' => '');
     try {
         $meta = new UserMetaController();
         $meta->getUsermetaAction($uid, 'portrait');
         $portrait = $meta->resource->meta_value;
         foreach ($portraitAddresses as $portraitSize => &$value) {
             if (file_exists(PUBLIC_PATH . $this->portraitSavePaths[$portraitSize] . '/' . $portrait . '.jpg')) {
                 $value = $this->url->get($this->portraitSavePaths[$portraitSize] . '/' . $portrait . '.jpg');
             }
         }
     } catch (ResourceException $e) {
         if ($e->getCode() != 404) {
             throw $e;
         }
     }
     $this->response(200, 'OK', $portraitAddresses);
 }