Sharing: redirect to download after authentification if requested

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-02-28 17:05:55 +01:00
parent 0cfdf4748f
commit fb890807c0
No known key found for this signature in database
GPG Key ID: FB5ACEED51955BF8
2 changed files with 9 additions and 6 deletions

View File

@ -170,10 +170,11 @@ class ShareController extends Controller {
* *
* Authenticates against password-protected shares * Authenticates against password-protected shares
* @param string $token * @param string $token
* @param string $redirect
* @param string $password * @param string $password
* @return RedirectResponse|TemplateResponse|NotFoundResponse * @return RedirectResponse|TemplateResponse|NotFoundResponse
*/ */
public function authenticate($token, $password = '') { public function authenticate($token, $redirect, $password = '') {
// Check whether share exists // Check whether share exists
try { try {
@ -184,7 +185,9 @@ class ShareController extends Controller {
$authenticate = $this->linkShareAuth($share, $password); $authenticate = $this->linkShareAuth($share, $password);
if($authenticate === true) { if ($authenticate === true && $redirect === 'download') {
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.downloadShare', array('token' => $token)));
} else if ($authenticate === true) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token))); return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token)));
} }
@ -294,7 +297,7 @@ class ShareController extends Controller {
// Share is password protected - check whether the user is permitted to access the share // Share is password protected - check whether the user is permitted to access the share
if ($share->getPassword() !== null && !$this->linkShareAuth($share)) { if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
array('token' => $token))); array('token' => $token, 'redirect' => 'preview')));
} }
if (!$this->validateShare($share)) { if (!$this->validateShare($share)) {
@ -480,7 +483,7 @@ class ShareController extends Controller {
// Share is password protected - check whether the user is permitted to access the share // Share is password protected - check whether the user is permitted to access the share
if ($share->getPassword() !== null && !$this->linkShareAuth($share)) { if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
['token' => $token])); ['token' => $token, 'redirect' => 'download']));
} }
$files_list = null; $files_list = null;

View File

@ -116,7 +116,7 @@ $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(f
throw new \OC\HintException('App file sharing is not enabled'); throw new \OC\HintException('App file sharing is not enabled');
} }
}); });
$this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate')->post()->action(function($urlParams) { $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate/{redirect}')->post()->action(function($urlParams) {
if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
$app->dispatch('ShareController', 'authenticate'); $app->dispatch('ShareController', 'authenticate');
@ -124,7 +124,7 @@ $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenti
throw new \OC\HintException('App file sharing is not enabled'); throw new \OC\HintException('App file sharing is not enabled');
} }
}); });
$this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate')->get()->action(function($urlParams) { $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate/{redirect}')->get()->action(function($urlParams) {
if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
$app->dispatch('ShareController', 'showAuthenticate'); $app->dispatch('ShareController', 'showAuthenticate');