public function actionRemove()
 {
     $this->prepareUser();
     $this->prepareToken();
     $user_device = UserDevice::model()->findByAttributes(array('ID_user' => $this->tiUser->ID, 'Device_token' => $this->token));
     try {
         $user_device->delete();
     } catch (Exception $e) {
         new Error(5, NULL, $e->getMessage());
     }
     new Error(1);
 }
Exemple #2
0
 /**
  * 从session中获取用户信息
  */
 public function getUserFromSession()
 {
     $user = Yii::app()->session["user"];
     if (empty($user)) {
         return false;
     }
     // 获取web端设备id
     $device = UserDevice::model()->findByAttributes(array('user_id' => $user['id'], 'user_device_type' => 1));
     if (empty($device)) {
         return false;
     }
     $this->_user = $user;
     $this->_device = $device;
     return $user;
 }
 /**
  * 获取设备列表
  */
 public function getDevices($pageSize, $currentPage)
 {
     $devices = MiniUserDevice::getInstance()->getAllDevices($pageSize, $currentPage);
     $data = array();
     foreach ($devices as $device) {
         $dev = array();
         $user = MiniUser::getInstance()->getUser($device['user_id']);
         $dev['is_admin'] = $user['is_admin'];
         $dev['device_id'] = $device['id'];
         $dev['user_id'] = $device['user_id'];
         $dev['userName'] = $user['nick'];
         $dev['avatar'] = $user['avatar'];
         $dev['userDeviceType'] = $device['user_device_type'];
         $dev['userDeviceName'] = $device['user_device_name'];
         $dev['lastLoginTime'] = $device['updated_at'];
         array_push($data, $dev);
     }
     $this->list['list'] = $data;
     $this->list['total'] = UserDevice::model()->count();
     return $this->list;
 }
Exemple #4
0
 /**
  * 
  * 外部调用入口
  * @param bool $isParentId
  */
 public function invoke($isParentId = true)
 {
     // TODO 应该使用path创建
     $device = UserDevice::model()->find("user_id={$this->_userId} and user_device_type=1");
     $this->_deviceId = $device["id"];
     $this->_operator = $this->_userId;
     //
     // 空间检查
     //
     $this->handleSpace();
     if ($this->_parentId == 0) {
         $this->_path = "/{$this->_userId}/{$this->cname}";
     } elseif ($isParentId) {
         $parent = UserFile::model()->findByPk($this->_parentId);
         if (empty($parent)) {
             $this->handleResult(false, 3, "父目录不存在");
             return;
         }
         if ($parent["file_type"] == 0) {
             $this->handleResult(false, 3, "父目录不存在");
             return;
         }
         $this->_path = $parent["file_path"] . "/" . $this->cname;
         $this->_userId = $parent['user_id'];
     } else {
         $this->_path = "/{$this->_userId}/{$this->_path}";
     }
     //
     // 命名检查
     //
     if (CUtils::checkNameInvalid($this->_path) != 0) {
         $this->result["msg"] = "命名不能包含下列字符串: ^|?*\\<\":>";
         return;
     }
     //
     // 检查是否存在
     //
     $file = UserFile::model()->find(array('condition' => 'file_path=:file_path', 'params' => array(':file_path' => $this->_path)));
     if ($file) {
         if ($file["is_deleted"] == 0) {
             $this->result["message"] = "文件夹已经存在";
             return;
         }
     }
     $this->_path = CUtils::convertStandardPath($this->_path);
     //
     // 共享检查
     //
     $index = strlen("/{$this->_userId}");
     $path = substr_replace($this->_path, "", 0, $index);
     if ($this->share_filter->handlerCheck($this->_userId, $path)) {
         $this->_userId = $this->share_filter->master;
         $this->_path = '/' . $this->_userId . $this->share_filter->_path;
     }
     $this->cid = $this->handleCreateByPath($this->_path);
     $this->result["state"] = true;
     $this->result["code"] = 0;
     $this->result["message"] = "创建文件夹成功";
     $this->result["cname"] = $this->cname;
     $this->result['aid'] = $this->aid;
     $this->result['cid'] = $this->cid;
 }
Exemple #5
0
 /**
  * 全部还原
  */
 public function revertFileAll()
 {
     $models = $this->findAllByAttributes(array('is_deleted' => 1));
     $device_id = Yii::app()->session["deviceId"];
     foreach ($models as $model) {
         $shareFilter = MSharesFilter::init();
         $shareFilter->handlerCheckByFile($model['user_id'], $model);
         $user_id = $model['user_id'];
         $path = $model['file_path'];
         $context = $path;
         $event_uuid = MiniUtil::getEventRandomString(46);
         $action = 0;
         // 修改文件
         if ($model['file_type'] == 0) {
             //
             // 如果是文件,需要创建版本
             //
             $user = Yii::app()->session['user'];
             $device = UserDevice::model()->findByUserIdAndType($user['id'], CConst::DEVICE_WEB);
             $deviceName = $device["user_device_name"];
             $this->_saveFileMeta($path, $model['version_id'], $user['id'], $user['name'], CConst::WEB_RESTORE, $deviceName, $model['file_size']);
             $action = CConst::CREATE_FILE;
             $version = FileVersion::model()->findByPk($model["version_id"]);
             $context = array("hash" => $version['file_signature'], "rev" => (int) $model["version_id"], "bytes" => (int) $model["file_size"]);
             $context = serialize($context);
         }
         $model['event_uuid'] = $event_uuid;
         $model["is_deleted"] = 0;
         $model->save();
         MiniEvent::getInstance()->createEvent($user_id, $device_id, $action, $path, $context, $event_uuid, $shareFilter->type);
     }
     return true;
 }
Exemple #6
0
 /**
  *
  * 用户修改密码后,把此前的Token进行清理
  * 以便强制其它设备重新登陆,仅用于更新用户密码的场景updatePassword
  * @param string $userId
  */
 public function cleanByUserId($userId)
 {
     $devices = UserDevice::model()->findAll("user_id=:userId", array("userId" => $userId));
     foreach ($devices as $device) {
         $deviceId = $device["id"];
         $this->deleteToken($deviceId);
     }
 }
 /**
  * 根据设备类型查找设备
  * 分页获取数据
  */
 public function getDeviceByType($deviceType, $pageSize, $currentPage)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "user_device_type=:user_device_type";
     $criteria->params = array("user_device_type" => $deviceType);
     $criteria->limit = $pageSize;
     $criteria->offset = ($currentPage - 1) * $pageSize;
     $criteria->order = "-id";
     $items = UserDevice::model()->findAll($criteria);
     $total = UserDevice::model()->count($criteria);
     $data = array();
     if ($total == 0) {
         return null;
     } else {
         $data['list'] = $this->db2list($items);
         $data['total'] = $total;
         return $data;
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = UserDevice::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.'));
     }
     return $model;
 }
 /**
  *
  * 创建权限
  *
  * @since 1.0.7
  */
 public function createEvent($userId, $action, $file_path, $content)
 {
     $device = UserDevice::model()->findByUserIdAndType($userId, 1);
     $deviceId = $device["id"];
     $event_uuid = MiniUtil::getEventRandomString(46);
     MiniEvent::getInstance()->createEvent($userId, $deviceId, $action, $file_path, $content, $event_uuid);
 }