Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix #390 Dropbox plugin. Missing one item each time
Browse files Browse the repository at this point in the history
Remove user name / password, it's useless. Store tokens in a per-user file.
  • Loading branch information
cdujeu committed Dec 16, 2013
1 parent 22de28b commit a303594
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
18 changes: 12 additions & 6 deletions core/src/plugins/access.dropbox/class.dropboxAccessDriver.php
Expand Up @@ -57,7 +57,7 @@ public function initRepository()
if(!empty($_SESSION["OAUTH_DROPBOX_TOKENS"])) return;

// TOKENS IN FILE ?
$tokens = $this->getTokens($this->repository->getId());
$tokens = $this->getTokens();
if (!empty($tokens)) {
$_SESSION["OAUTH_DROPBOX_TOKENS"] = $tokens;
return;
Expand Down Expand Up @@ -87,7 +87,7 @@ public function initRepository()
$tokens = $oauth->getAccessToken();
$_SESSION['DROPBOX_NEGOCIATION_STATE'] = 3;
$_SESSION['OAUTH_DROPBOX_TOKENS'] = $tokens;
$this->setTokens($this->repository->getId(), $tokens);
$this->setTokens($tokens);
return;
}

Expand All @@ -107,13 +107,19 @@ public function isWriteable($dir, $type = "dir")
return true;
}

public function getTokens($repositoryId)
public function getTokens()
{
return AJXP_Utils::loadSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_tokens");
$repositoryId = $this->repository->getId();
if(AuthService::usersEnabled()) $userId = AuthService::getLoggedUser()->getId();
else $userId = "shared";
return AJXP_Utils::loadSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens");
}
public function setTokens($repositoryId, $oauth_tokens)
public function setTokens($oauth_tokens)
{
return AJXP_Utils::saveSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_tokens", $oauth_tokens, true);
$repositoryId = $this->repository->getId();
if(AuthService::usersEnabled()) $userId = AuthService::getLoggedUser()->getId();
else $userId = "shared";
return AJXP_Utils::saveSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens", $oauth_tokens, true);
}

}
5 changes: 3 additions & 2 deletions core/src/plugins/access.dropbox/class.dropboxWrapper.php
Expand Up @@ -63,7 +63,8 @@ public function initPath($ajxpPath)
self::$oauth->setToken($_SESSION["OAUTH_DROPBOX_TOKENS"]);
self::$dropbox = new Dropbox_API(self::$oauth);
}
$path = parse_url($ajxpPath, PHP_URL_PATH);
$parts = AJXP_Utils::safeParseUrl($ajxpPath);
$path = $parts["path"];
if($path == "") return "/";
return $path;
}
Expand Down Expand Up @@ -205,7 +206,7 @@ public function dir_opendir($path, $options)
public function dir_readdir()
{
//return false;
if(self::$crtDirIndex == count(self::$crtDirContent)-1) return false;
if(self::$crtDirIndex == count(self::$crtDirContent)) return false;
$meta = self::$crtDirContent[self::$crtDirIndex];
self::$crtDirIndex ++;
return basename($meta["path"]);
Expand Down
2 changes: 0 additions & 2 deletions core/src/plugins/access.dropbox/manifest.xml
Expand Up @@ -8,8 +8,6 @@
<server_settings>
<param name="CONSUMER_KEY" type="string" label="CONF_MESSAGE[Consumer Key]" description="CONF_MESSAGE[Key]" mandatory="true"/>
<param name="CONSUMER_SECRET" type="string" label="CONF_MESSAGE[Consumer Secret]" description="CONF_MESSAGE[Secret]" mandatory="true"/>
<param name="USER" type="string" label="CONF_MESSAGE[User Mail]" description="CONF_MESSAGE[User account]" mandatory="true"/>
<param name="PASS" type="password" label="CONF_MESSAGE[Password]" description="CONF_MESSAGE[User Password]" mandatory="true"/>
</server_settings>
<class_definition filename="plugins/access.dropbox/class.dropboxAccessDriver.php" classname="dropboxAccessDriver"/>
<registry_contributions>
Expand Down

0 comments on commit a303594

Please sign in to comment.