Example #1
0
 function share($hasp = null)
 {
     $result = array("data" => array(), "error" => 1);
     if (empty($hasp)) {
         $user_id = @$this->request->data['user_id'];
         $folder_id = @$this->request->data['folder_id'];
         $this->user_id = $this->User->getUserIdByAPIToken(@$this->request->data['api_token']);
     } else {
         $secret = explode(self::PREFIX, Security::cipher(base64_decode($hasp), Configure::read('Security.salt')));
         if (count($secret) < 4) {
             return $this->redirect(self::APP_STORE);
         }
         $this->user_id = $secret[0];
         $user_id = $secret[1];
         $folder_id = $secret[2];
     }
     if (empty($user_id) || empty($folder_id) || empty($this->user_id)) {
         if (empty($hasp)) {
             return $this->responseOk($result);
         } else {
             return $this->redirect(self::APP_STORE);
         }
     } else {
         $my_user = $this->User->findById($this->user_id);
         $user = $this->User->findById($user_id);
         $folder = $this->FolderUser->find("first", array("conditions" => array("FolderUser.id" => $folder_id, "FolderUser.user_id" => $this->user_id)));
         if (empty($user) || empty($folder) || empty($my_user)) {
             if (empty($hasp)) {
                 return $this->responseOk($result);
             } else {
                 return $this->redirect(self::APP_STORE);
             }
         }
     }
     if (empty($hasp)) {
         $str = $this->randomString();
         $hasp = $this->safe_b64encode(Security::cipher($this->user_id . self::PREFIX . $user_id . self::PREFIX . $folder_id . self::PREFIX . $str, Configure::read('Security.salt')));
         $link = Router::url('/', true) . "Kaopass/share/{$hasp}";
         $result["error"] = 0;
         $result["data"] = $link;
         return $this->responseOk($result);
     } else {
         APP::import("Model", array("FolderShare"));
         $folderShare = new FolderShare();
         $folderShareData = $folderShare->find("first", array("conditions" => array("FolderShare.folder_id" => $folder_id, "FolderShare.user_id" => $user_id)));
         if ($folderShareData) {
             return $this->redirect(self::APP_KAOPASS);
         }
         $dataSave = array('user_id' => $user_id, "folder_id" => $folder_id);
         $folderShare->create();
         $folderShare->save($dataSave);
         return $this->redirect(self::APP_KAOPASS);
     }
 }
Example #2
0
 /**
  *  share folder secret for user
  */
 function addFolderFriend()
 {
     APP::import("Model", array("FolderShare"));
     $folderShare = new FolderShare();
     $dataRequest = @$this->request->data;
     $folder_id = @$dataRequest['folder_id'];
     $user_id = @$dataRequest['user_id'];
     if (!$folder_id) {
         return $this->responseNg('invalid params.');
     }
     $folder = $this->FolderUser->find("first", array("conditions" => array("FolderUser.id" => $folder_id)));
     if (empty($folder)) {
         return $this->responseNg('foler not exists');
     }
     if ($folder['FolderUser']['user_id'] == $user_id) {
         return $this->responseok('you can\'t share your folder yourself.');
     }
     $folderShareData = $folderShare->find("first", array("conditions" => array("FolderShare.folder_id" => $folder_id, "FolderShare.user_id" => $user_id)));
     if ($folderShareData) {
         return $this->responseok("メールで友達を招待する");
         // validate
     }
     $dataSave = array('user_id' => $user_id, "folder_id" => $folder_id);
     $folderShare->create();
     if ($folderShare->save($dataSave)) {
         return $this->responseok("");
     } else {
         return $this->responseng('faild to share.');
     }
 }