diff --git a/lib/Helper/ValidateHelper.php b/lib/Helper/ValidateHelper.php index 54e7ad0bbe..ecda57d160 100644 --- a/lib/Helper/ValidateHelper.php +++ b/lib/Helper/ValidateHelper.php @@ -164,6 +164,12 @@ public function validateBase64(string $base64, int $type = self::TYPE_TO_SIGN): if ($withMime[0][1] !== 'base64') { throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)])); } + + if ($type === self::TYPE_TO_SIGN) { + if ($withMime[0][0] !== 'data:application/pdf') { + throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)])); + } + } $base64 = $withMime[1]; } $string = base64_decode($base64); @@ -174,10 +180,14 @@ public function validateBase64(string $base64, int $type = self::TYPE_TO_SIGN): $mimeType = $this->mimeTypeDetector->detectString($string); - if ($type === self::TYPE_TO_SIGN && $mimeType !== 'application/pdf') { - throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)])); - } elseif ($mimeType !== 'image/png' && in_array($type, [self::TYPE_VISIBLE_ELEMENT_USER, self::TYPE_VISIBLE_ELEMENT_PDF])) { - throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)])); + if ($type === self::TYPE_TO_SIGN) { + if ($mimeType !== 'application/pdf') { + throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)])); + } + } elseif ($mimeType !== 'image/png') { + if (in_array($type, [self::TYPE_VISIBLE_ELEMENT_USER, self::TYPE_VISIBLE_ELEMENT_PDF])) { + throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)])); + } } } diff --git a/src/Components/Draw/Draw.vue b/src/Components/Draw/Draw.vue index 74625752dd..899cbe3632 100644 --- a/src/Components/Draw/Draw.vue +++ b/src/Components/Draw/Draw.vue @@ -100,6 +100,7 @@ export default { .draw-signature { .modal-container { width: unset !important; + height: unset !important; } } diff --git a/src/views/SignPDF/_partials/Sign.vue b/src/views/SignPDF/_partials/Sign.vue index fcfec66190..2b16540fc5 100644 --- a/src/views/SignPDF/_partials/Sign.vue +++ b/src/views/SignPDF/_partials/Sign.vue @@ -35,6 +35,12 @@

+ import { get, isEmpty, pick } from 'lodash-es' -import { showError } from '@nextcloud/dialogs' +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' +import { showError, showSuccess } from '@nextcloud/dialogs' import { service as sigantureService } from '../../../domains/signatures/index.js' import { service as signService } from '../../../domains/sign/index.js' import { onError } from '../../../helpers/errors.js' @@ -64,6 +72,7 @@ import PasswordManager from './ModalPasswordManager.vue' import SMSManager from './ModalSMSManager.vue' import EmailManager from './ModalEmailManager.vue' import PreviewSignature from '../../../Components/PreviewSignature/PreviewSignature.vue' +import Draw from '../../../Components/Draw/Draw.vue' const SIGN_METHODS = Object.freeze({ PASSWORD: 'PasswordManager', @@ -79,6 +88,7 @@ export default { SMSManager, EmailManager, PreviewSignature, + Draw, }, props: { uuid: { @@ -230,6 +240,25 @@ export default { } catch (err) { } }, + async saveSignature(value) { + try { + const res = await axios.post(generateOcsUrl('/apps/libresign/api/v1/account/signature/elements'), { + elements: [ + { + file: { + base64: value, + }, + type: 'signature', + }, + ], + }) + await this.loadSignatures() + showSuccess(res.data.message) + } catch (err) { + onError(err) + } + this.modals.createSignature = false + }, async signWithPassword(password) { this.loading = true