Catch error when trying to upload empty or invalid avatar

This commit is contained in:
Manfred Hoffmann
2021-04-20 07:42:58 +02:00
committed by GitHub
parent 6f8f5aff33
commit ae39544e10
38 changed files with 100 additions and 2 deletions

View File

@@ -33,8 +33,14 @@ class AvatarFileController extends BaseController
$this->checkCSRFParam();
$user = $this->getUser();
if (! $this->avatarFileModel->uploadImageFile($user['id'], $this->request->getFileInfo('avatar'))) {
$this->flash->failure(t('Unable to upload files, check the permissions of your data folder.'));
if (! $this->request->getFileInfo('avatar')['name']) {
$this->flash->failure(t('You must select a file to upload as your avatar!'));
} elseif (! $this->avatarFileModel->isAvatarImage($this->request->getFileInfo('avatar')['name'])) {
$this->flash->failure(t('The file you uploaded is not a valid image! (Only *.gif, *.jpg, *.jpeg and *.png are allowed!)'));
} else {
if (! $this->avatarFileModel->uploadImageFile($user['id'], $this->request->getFileInfo('avatar'))) {
$this->flash->failure(t('Unable to upload files, check the permissions of your data folder.'));
}
}
$this->renderResponse($user['id']);