Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public function actionIndex(array $variables = array())
if ($variables and $variables["crypt"]) {
$options = craft()->secureAssetDownload->decodeUrlParam($variables["crypt"]);

if (gettype($options)!='array') {
throw new HttpException('404', 'Invalid asset URL');
}

if (!craft()->secureAssetDownload->isDownloadAllowed($options)) {
throw new Exception(Craft::t("You do not have permission to download this file"));
}
Expand Down
17 changes: 17 additions & 0 deletions secureassetdownload/services/SecureAssetDownloadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public function getUrl($criteria)
$options['userGroupId'] = $criteria['userGroupId'];
}

$options['onetime'] = (isset($criteria['onetime']) ? $criteria['onetime'] : false);
if ($options['onetime']) {
$options['duration'] = (isset($criteria['duration']) ? $criteria['duration'] : 60);
$options['time'] = time();
}

$urlParam = $this->encodeUrlParam($options);

return UrlHelper::getSiteUrl('secureAssetDownload/' . $urlParam);
Expand Down Expand Up @@ -99,6 +105,17 @@ public function isDownloadAllowed(array $options = array())
return false;
}

if ($options['onetime']) {
$time = isset($options['duration']) ? $options['duration'] : $key = craft()->plugins->getPlugin("secureAssetDownload")->getSettings()->timeKey;
if ( (time() - $options['time']) >= $time ) {
throw new Exception(Craft::t("Link Expired"));
return false;
}
// throw new Exception(Craft::t( time() - $options['time'] . " " . $time));
$options['time'] -= $time;
// throw new Exception(Craft::t("\$options['onetime']: " . $options['onetime'] . " | \$options['time']: " . $options['time'] . " | \$time: " . $time . " | time: " . time() ));
}

if (!craft()->userSession->isLoggedIn()) {
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions secureassetdownload/templates/_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@
required: true,
errors: ''
}) }}
{{ forms.textField({
label: "Time"|t,
id: 'timeKey',
name: 'timeKey',
instructions: "Global Time for one-time-downloads"|t,
value: settings.timeKey,
autofocus: true,
first: true,
required: true,
errors: ''
}) }}