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

[TASK] Implemented frontend validation of upload file sizes

parent 18a8240f
No related branches found
No related tags found
1 merge request!7Feature max file size
......@@ -40,6 +40,7 @@ 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;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* The joblist plugin controller
......@@ -137,10 +138,6 @@ 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);
......@@ -198,6 +195,9 @@ class JoblistController extends ActionController {
$this->view->assign('applyData', $applyData);
$this->view->assign('maxFileSize', $this->settings['allowedMaxFileSize']);
$this->view->assign(
'maxFileSizeMessage', LocalizationUtility::translate('error.maxFileSizeMessage', 'sg_jobs')
);
}
/**
......@@ -216,17 +216,6 @@ class JoblistController extends ActionController {
$this->redirect('applyForm', NULL, NULL, ['error' => $exceptionMessage]);
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)) {
$this->redirect('applyForm', NULL, NULL, ['error' => $exceptionMessage]);
exit;
}
$propertyMappingConfiguration = $this->arguments->getArgument('applyData')->getPropertyMappingConfiguration();
$propertyMappingConfiguration->forProperty('job')->allowAllProperties();
......@@ -276,6 +265,7 @@ class JoblistController extends ActionController {
* @param JobApplication $applyData
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/
public function applyAction(JobApplication $applyData) {
$folderName = $this->request->getArgument('folderName');
......@@ -481,13 +471,15 @@ class JoblistController extends ActionController {
/**
* checks for allowed maximum file sizes
*
* @param array $applyData
* @param JobApplication $applyData
* @return bool
* @throws \InvalidArgumentException
*/
private function checkFileSizes(array $applyData): bool {
$coverLetterSize = (int) $applyData['coverLetter']['size'] / 1000;
$cvSize = (int) $applyData['cv']['size'] / 1000;
$certificateSize = (int) $applyData['certificate']['size'] / 1000;
private function checkFileSizes($applyData): bool {
$coverLetterSize = (int) $applyData->getCoverLetter()->getOriginalResource()->getSize() / 1000;
$cvSize = (int) $applyData->getCv()->getOriginalResource()->getSize() / 1000;
$certificateSize = (int) $applyData->getCertificate()->getOriginalResource()->getSize() / 1000;
$allowedMaxFileSize = (int) $this->settings['allowedMaxFileSize'];
if ($allowedMaxFileSize === 0) {
......
......@@ -138,6 +138,10 @@
<source>Please select one of the following pages:</source>
<target>Bitte wählen Sie eine der folgenden Seiten aus:</target>
</trans-unit>
<trans-unit id="error.maxFileSizeMessage" approved="yes">
<source>The selected File is too big!</source>
<target>Die ausgewählte Datei ist zu groß!</target>
</trans-unit>
<trans-unit id="frontend.allVacancies" approved="yes">
<source>All vacancies</source>
<target>Alle offenen Stellen</target>
......
......@@ -105,6 +105,9 @@
<trans-unit id="backend.selectRootPage">
<source>Please select one of the following pages:</source>
</trans-unit>
<trans-unit id="error.maxFileSizeMessage">
<source>The selected File is too big!</source>
</trans-unit>
<trans-unit id="frontend.allVacancies">
<source>All vacancies</source>
</trans-unit>
......
......@@ -61,6 +61,10 @@
<source>Zip</source>
<target>邮编</target>
</trans-unit>
<trans-unit id="error.maxFileSizeMessage" approved="yes">
<source>The selected File is too big!</source>
<target>The selected File is too big!</target>
</trans-unit>
<trans-unit id="frontend.allVacancies" approved="yes">
<source>All vacancies</source>
<target>所有职位机会</target>
......
......@@ -13,6 +13,9 @@ export default class SgJobs {
constructor() {
$('.remove-file').on('click', this._removeFile);
$('#sgjobs-joblist').on('change', '.sgjobs-select', this._filterJoblist);
$('#apply-cover-letter').on('change', this._checkFileSize);
$('#apply-cv').on('change', this._checkFileSize);
$('#apply-certificate').on('change', this._checkFileSize);
}
/**
......@@ -44,4 +47,11 @@ export default class SgJobs {
_filterJoblist() {
$('#sgjobs-filter').submit();
}
_checkFileSize() {
if (this.files[0].size > document.querySelector('#maxFileSize').getAttribute('data-maxFilesize') * 1000) {
alert(document.querySelector('#maxFileSizeMessage').getAttribute('data-maxFileSizeMessage'));
this.value = "";
};
}
}
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