Skip to content

Commit

Permalink
Make possible define signature at sign page
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Jan 18, 2024
1 parent 1d651b9 commit edfa08a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
18 changes: 14 additions & 4 deletions lib/Helper/ValidateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)]));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Components/Draw/Draw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default {
.draw-signature {
.modal-container {
width: unset !important;
height: unset !important;
}
}
</style>
Expand Down
31 changes: 30 additions & 1 deletion src/views/SignPDF/_partials/Sign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
</p>
</div>
</div>
<Draw v-if="modals.createSignature"
:draw-editor="true"
:text-editor="true"
:file-editor="true"
@save="saveSignature"
@close="onModalClose('createSignature')" />
<PasswordManager v-if="modals.password"
v-bind="{ hasPassword, signMethod }"
@change="signWithPassword"
Expand All @@ -56,14 +62,17 @@

<script>
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'
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',
Expand All @@ -79,6 +88,7 @@ export default {
SMSManager,
EmailManager,
PreviewSignature,
Draw,
},
props: {
uuid: {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit edfa08a

Please sign in to comment.