[Share 2.0] Add fetching link shares to share manager

This commit is contained in:
Roeland Jago Douma 2016-01-14 16:44:59 +01:00
parent 647d8ea5de
commit e40d21673e
3 changed files with 71 additions and 12 deletions

View File

@ -284,7 +284,11 @@ class DefaultShareProvider implements IShareProvider {
throw new ShareNotFound(); throw new ShareNotFound();
} }
try {
$share = $this->createShare($data); $share = $this->createShare($data);
} catch (InvalidShare $e) {
throw new ShareNotFound();
}
return $share; return $share;
} }
@ -328,13 +332,34 @@ class DefaultShareProvider implements IShareProvider {
} }
/** /**
* Get a share by token and if present verify the password * Get a share by token
* *
* @param string $token * @param string $token
* @param string $password * @return IShare
* @param Share * @throws ShareNotFound
*/ */
public function getShareByToken($token, $password = null) { public function getShareByToken($token) {
$qb = $this->dbConn->getQueryBuilder();
$cursor = $qb->select('*')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
->execute();
$data = $cursor->fetch();
if ($data === false) {
throw new ShareNotFound();
}
try {
$share = $this->createShare($data);
} catch (InvalidShare $e) {
throw new ShareNotFound();
}
return $share;
} }
/** /**

View File

@ -103,11 +103,11 @@ interface IShareProvider {
public function getSharedWithMe(IUser $user, $shareType = null); public function getSharedWithMe(IUser $user, $shareType = null);
/** /**
* Get a share by token and if present verify the password * Get a share by token
* *
* @param string $token * @param string $token
* @param string $password * @return IShare
* @param Share * @throws ShareNotFound
*/ */
public function getShareByToken($token, $password = null); public function getShareByToken($token);
} }

View File

@ -665,13 +665,47 @@ class Manager {
* Get the share by token possible with password * Get the share by token possible with password
* *
* @param string $token * @param string $token
* @param string $password
*
* @return Share * @return Share
* *
* @throws ShareNotFound * @throws ShareNotFound
*/ */
public function getShareByToken($token, $password=null) { public function getShareByToken($token) {
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK);
$share = $provider->getShareByToken($token);
//TODO check if share expired
return $share;
}
/**
* Verify the password of a public share
*
* @param IShare $share
* @param string $password
* @return bool
*/
public function checkPassword(IShare $share, $password) {
if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) {
//TODO maybe exception?
return false;
}
if ($password === null || $share->getPassword() === null) {
return false;
}
$newHash = '';
if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
return false;
}
if (!empty($newHash)) {
//TODO update hash!
}
return true;
} }
/** /**