Skip to content
Snippets Groups Projects
Commit f346b95c authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Checking for file size, preserving form values

parent 9184fc96
No related branches found
No related tags found
1 merge request!7Feature max file size
......@@ -39,11 +39,15 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use TYPO3\CMS\Extbase\Mvc\Request;
/**
* The joblist plugin controller
*/
class JoblistController extends ActionController {
// the array key for the error message in the post array
const ERROR_KEY_IN_POST = 'error';
/**
* @var \SGalinski\SgJobs\Domain\Repository\CompanyRepository
* @inject
......@@ -133,6 +137,10 @@ class JoblistController extends ActionController {
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
*/
public function applyFormAction(JobApplication $applyData = NULL, $error = NULL, $jobId = NULL) {
if ($error === NULL && isset($_POST[self::ERROR_KEY_IN_POST])) {
$error = $_POST[self::ERROR_KEY_IN_POST];
}
if ($error !== NULL && $error !== '') {
$this->view->assign('internalError', $error);
$this->request->setArgument('error', NULL);
......@@ -189,6 +197,7 @@ class JoblistController extends ActionController {
}
$this->view->assign('applyData', $applyData);
$this->view->assign('maxFileSize', $this->settings['allowedMaxFileSize']);
}
/**
......@@ -204,9 +213,23 @@ class JoblistController extends ActionController {
$uniqueFolderName = $this->request->getArgument('folderName');
} catch (NoSuchArgumentException $exception) {
$exceptionMessage = 'Eine Datei konnte nicht hochgeladen werden. Ist diese eventuell zu groß?';
$this->redirect('applyForm', NULL, NULL, ['error' => $exceptionMessage]);
$_POST[self::ERROR_KEY_IN_POST] = $exceptionMessage;
$this->forwardToReferringRequest();
exit;
}
/** @var array $applyDataArray */
$applyDataArray = $this->request->getArgument('applyData');
$exceptionMessage = 'Bitte beachten Sie die maximale Upload Größe von '
. (int) ($this->settings['allowedMaxFileSize'] / 1000) . 'MB';
if (!$this->checkFileSizes($applyDataArray)) {
$_POST[self::ERROR_KEY_IN_POST] = $exceptionMessage;
$this->forwardToReferringRequest();
exit;
}
$propertyMappingConfiguration = $this->arguments->getArgument('applyData')->getPropertyMappingConfiguration();
$propertyMappingConfiguration->forProperty('job')->allowAllProperties();
......@@ -457,4 +480,30 @@ class JoblistController extends ActionController {
$this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
}
}
/**
* checks for allowed maximum file sizes
*
* @param array $applyData
* @return bool
*/
private function checkFileSizes(array $applyData): bool {
$coverLetterSize = (int) $applyData['coverLetter']['size'] / 1000;
$cvSize = (int) $applyData['cv']['size'] / 1000;
$certificateSize = (int) $applyData['certificate']['size'] / 1000;
$allowedMaxFileSize = (int) $this->settings['allowedMaxFileSize'];
if ($allowedMaxFileSize === 0) {
return TRUE;
}
if ($allowedMaxFileSize < $coverLetterSize
|| $allowedMaxFileSize < $cvSize
|| $allowedMaxFileSize < $certificateSize) {
return FALSE;
}
return TRUE;
}
}
......@@ -17,6 +17,8 @@ plugin.tx_sgjobs {
allowedFileExtensions = pdf
# cat=plugin.tx_sgjobs/other; type=string; label=Allowed mime types for uploads in the Fluid template (comma separated)
allowedMimeTypes = application/pdf
# cat=plugin.tx_sgjobs/other; type=string; label=Allowed maximum file size for uploads in kB
allowedMaxFileSize = 5000
}
pagebrowser.settings {
......
......@@ -24,6 +24,7 @@ plugin.tx_sgjobs {
settings {
allowedFileExtensions = {$plugin.tx_sgjobs.settings.allowedFileExtensions}
allowedMimeTypes = {$plugin.tx_sgjobs.settings.allowedMimeTypes}
allowedMaxFileSize = {$plugin.tx_sgjobs.settings.allowedMaxFileSize}
}
features {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment