Beispiel #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);
     }
 }
Beispiel #2
0
 /**
  * 检查用户名是否存在(该方法非响应资源型方法)
  *
  * @param string $username  用户名
  * @return bool             若用户名存在则返回true, 否者为false
  */
 public function getUsernameExists($username)
 {
     $this->validation->validate('username', $username);
     $user = Users::findFirst(array('conditions' => 'username = ?0', 'bind' => array($username)));
     return (bool) $user;
 }
Beispiel #3
0
 /**
  * 投递站内信
  *
  * @param integer $send_uid       发送者用户ID
  * @param string  $content        消息内容
  * @param string  $msg_options    消息选项
  * @param integer $uid_or_gid     用户ID或用户组ID
  * @param string  $post_type      投递类型
  * @param string  $post_time      投递时间
  * @param integer $expiry         消息有效期(仅供显示, 不参与最终的失效计算)
  * @param string  $expiry_at_end  消息结束日期
  * @throws ResourceException
  * @throws \Itslove\Passport\Helper\ValidationException
  */
 public function postMessageAction($send_uid, $content, $msg_options, $uid_or_gid, $post_type, $post_time, $expiry, $expiry_at_end)
 {
     //判断发送者发送权限
     /** @var \Itslove\Passport\Models\Users $sendUser */
     if (!($sendUser = Users::findPrimary($send_uid)) || 0 == $sendUser->active) {
         throw new ResourceException('Forbidden', 403);
     }
     $msg = new Messages();
     $msg->send_UID = $this->validation->validate('id', $send_uid);
     $msg->content = $content;
     $msg->msg_options = $msg_options;
     $msg->post_type = $post_type;
     $msg->post_time = $this->validation->validate('datetime', $post_time);
     $msg->send_delete = 0;
     $msg->expiry = $this->validation->validate('uint', $expiry);
     $msg->expiry_at_end = $this->validation->validate('datetime', $expiry_at_end);
     switch ($msg->post_type) {
         case Messages::POST_TYPE_PRIVATE:
             $msg->GID = 0;
             $msgLog = new MessageLogs();
             $msgLog->rec_UID = $uid_or_gid;
             $msgLog->status = MessageLogs::STATUS_UNREAD;
             break;
         case Messages::POST_TYPE_PUBLIC:
             $msg->GID = $uid_or_gid;
             break;
         case Messages::POST_TYPE_GLOBAL:
             $msg->GID = 0;
             break;
         default:
             throw new ResourceException('Conflict', 409);
     }
     $this->db->begin();
     try {
         if (isset($msgLog) && false == Users::findPrimary($msgLog->rec_UID)) {
             throw new ResourceException('Not Found', 404);
         }
         if ($msg->create()) {
             $this->response(201, 'Created', array('msg_id' => $msg->msg_id));
             $this->response->setHeader('Location', 'message/' . $msg->msg_id);
         } else {
             throw new ResourceException('Internal Server Error', 500);
         }
         if (isset($msgLog)) {
             $msgLog->msg_id = $msg->msg_id;
             if (!$msgLog->create()) {
                 throw new ResourceException('Internal Server Error', 500);
             }
         }
         $this->db->commit();
     } catch (ResourceException $e) {
         $this->db->rollback();
         throw $e;
     }
 }