[Share 2.0] Add fetching link shares to share manager
This commit is contained in:
parent
647d8ea5de
commit
e40d21673e
|
@ -284,7 +284,11 @@ class DefaultShareProvider implements IShareProvider {
|
|||
throw new ShareNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$share = $this->createShare($data);
|
||||
} catch (InvalidShare $e) {
|
||||
throw new ShareNotFound();
|
||||
}
|
||||
|
||||
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 $password
|
||||
* @param Share
|
||||
* @return IShare
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,11 +103,11 @@ interface IShareProvider {
|
|||
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 $password
|
||||
* @param Share
|
||||
* @return IShare
|
||||
* @throws ShareNotFound
|
||||
*/
|
||||
public function getShareByToken($token, $password = null);
|
||||
public function getShareByToken($token);
|
||||
}
|
||||
|
|
|
@ -665,13 +665,47 @@ class Manager {
|
|||
* Get the share by token possible with password
|
||||
*
|
||||
* @param string $token
|
||||
* @param string $password
|
||||
*
|
||||
* @return Share
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue