Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Service/IdentifyMethod/SignatureMethod/TokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private function getGateway(string $gatewayName) {
throw new LibresignException('App Two-Factor Gateway is not installed.');

}
$gateway = $factory->getGateway($gatewayName);
if (!$gateway->getConfig()->isComplete()) {
$gateway = $factory->get($gatewayName);
if (!$gateway->isComplete()) {
throw new OCSForbiddenException($this->l10n->t('Gateway %s not configured on Two-Factor Gateway.', $gatewayName));
}
return $gateway;
Expand Down
3 changes: 2 additions & 1 deletion lib/Service/SignFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ public function requestCode(
continue;
}
/** @var IToken $signatureMethod */
$signatureMethod->requestCode($identify, $identifyMethod->getEntity()->getIdentifierKey());
$identifier = $identify ?: $identifyMethod->getEntity()->getIdentifierValue();
$signatureMethod->requestCode($identifier, $identifyMethod->getEntity()->getIdentifierKey());
return;
}
throw new LibresignException($this->l10n->t('Sending authorization code not enabled.'));
Expand Down
6 changes: 6 additions & 0 deletions src/store/signMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export const useSignMethodsStore = defineStore('signMethods', {
return Object.hasOwn(this.settings, 'sms')
&& this.settings.sms.needCode
},
needTokenCode() {
const tokenMethods = ['sms', 'whatsapp', 'signal', 'telegram', 'xmpp']
return tokenMethods.some(method =>
Object.hasOwn(this.settings, method) && this.settings[method].needCode
)
},
needCertificate() {
return this.certificateEngine === 'none' && !this.hasSignatureFile()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
-->
<template>
<NcDialog v-if="signMethodsStore.modal.sms"
:name="t('libresign', 'Sign with your cellphone number.')"
:name="t('libresign', 'Sign with your phone number.')"
@closing="signMethodsStore.closeModal('sms')">
<div v-if="newPhoneNumber" class="code-request">
<div v-if="tokenRequested" class="code-request">
<h3 class="phone">
{{ newPhoneNumber }}
</h3>

<NcTextField v-if="tokenRequested"
v-model="token"
<NcTextField v-model="token"
:disabled="loading"
name="code"
type="text" />
Expand All @@ -26,24 +25,18 @@
@change="sanitizeNumber" />
</div>
<template #actions>
<NcButton v-if="newPhoneNumber && !tokenRequested" :disabled="loading" @click="requestCode">
<NcButton v-if="!tokenRequested" :disabled="loading || newPhoneNumber.length < 10" @click="requestCode">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
</template>
{{ t('libresign', 'Request code.') }}
</NcButton>
<NcButton v-if="newPhoneNumber && tokenRequested" :disabled="loading" @click="sendCode">
<NcButton v-else :disabled="loading || token.length < 3" @click="sendCode">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
</template>
{{ t('libresign', 'Send code.') }}
</NcButton>
<NcButton v-if="!newPhoneNumber" :disabled="loading || newPhoneNumber.length < 10" @click="saveNumber">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
</template>
{{ t('libresign', 'Save your number.') }}
</NcButton>
</template>
</NcDialog>
</template>
Expand All @@ -61,14 +54,15 @@ import NcTextField from '@nextcloud/vue/components/NcTextField'

import { settingsService } from '../../../domains/settings/index.js'
import { useSignStore } from '../../../store/sign.js'
import { useSignMethodsStore } from '../../../store/signMethods.js'

const sanitizeNumber = val => {
val = val.replace(/\D/g, '')
return `+${val}`
}

export default {
name: 'ModalSMSManager',
name: 'ModalTokenManager',
components: {
NcDialog,
NcLoadingIcon,
Expand All @@ -78,19 +72,34 @@ export default {
props: {
phoneNumber: {
type: String,
required: true,
required: false,
default: '',
},
},
setup() {
const signStore = useSignStore()
return { signStore }
const signMethodsStore = useSignMethodsStore()
return { signStore, signMethodsStore }
},
data() {
return {
token: '',
newPhoneNumber: this.phoneNumber || '',
tokenRequested: false,
loading: false,
}
},
computed: {
activeTokenMethod() {
const tokenMethods = ['sms', 'whatsapp', 'signal', 'telegram', 'xmpp']
return tokenMethods.find(method =>
Object.hasOwn(this.signMethodsStore.settings, method)
) || 'sms'
},
activeIdentifyMethod() {
return this.activeTokenMethod
},
},
data: () => ({
token: '',
newPhoneNumber: this.phoneNumber,
tokenRequested: false,
loading: false,
}),
methods: {
async saveNumber() {
this.loading = true
Expand Down Expand Up @@ -123,22 +132,40 @@ export default {
await this.$nextTick()

try {
const params = {
identifyMethod: this.activeIdentifyMethod,
signMethod: this.activeTokenMethod,
}

if (this.signStore.document.fileId) {
const { data } = await axios.post(generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}/code', {
fileId: this.signStore.document.fileId,
}))
const { data } = await axios.post(
generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}/code', {
fileId: this.signStore.document.fileId,
}),
params
)
showSuccess(data.ocs.data.message)
} else {
const signer = this.signStore.document.signers.find(row => row.me) || {}
const { data } = await axios.post(generateOcsUrl('/apps/libresign/api/v1/sign/uuid/{fileId}/code', {
const signer = this.signStore.document.signers.find(row => row.me) || {}
const { data } = await axios.post(
generateOcsUrl('/apps/libresign/api/v1/sign/uuid/{uuid}/code', {
uuid: signer.sign_uuid,
}))
}),
params
)
showSuccess(data.ocs.data.message)
}
this.tokenRequested = true
} catch (err) {
showError(err.response.data.ocs.data.message)
} finally {
this.tokenRequested = true
} catch (err) {
const errorMessage = err.response?.data?.ocs?.data?.message || err.response?.data?.message || err.message

if (errorMessage && errorMessage.includes('Invalid configuration')) {
const method = this.activeTokenMethod.charAt(0).toUpperCase() + this.activeTokenMethod.slice(1)
showError(t('libresign', '{method} is not configured. Please contact your administrator.', { method }))
} else {
showError(errorMessage)
}
} finally {
this.loading = false
}
},
Expand Down
21 changes: 13 additions & 8 deletions src/views/SignPDF/_partials/Sign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@
:useModal="true"
:errors="errors"
@certificate:uploaded="onSignatureFileCreated" />
<SMSManager v-if="signMethodsStore.modal.sms"
:phone-number="user?.account?.phoneNumber"
@change="signWithSMSCode"
<TokenManager v-if="signMethodsStore.modal.sms"
:phone-number="user?.account?.phoneNumber || ''"
@change="signWithTokenCode"
@update:phone="val => $emit('update:phone', val)"
@close="signMethodsStore.closeModal('sms')" />
<EmailManager v-if="signMethodsStore.modal.emailToken"
Expand All @@ -156,7 +156,7 @@ import NcPasswordField from '@nextcloud/vue/components/NcPasswordField'
import NcRichText from '@nextcloud/vue/components/NcRichText'

import EmailManager from './ModalEmailManager.vue'
import SMSManager from './ModalSMSManager.vue'
import TokenManager from './ModalTokenManager.vue'
import Draw from '../../../Components/Draw/Draw.vue'
import Documents from '../../../views/Account/partials/Documents.vue'
import Signatures from '../../../views/Account/partials/Signatures.vue'
Expand All @@ -180,7 +180,7 @@ export default {
NcPasswordField,
NcRichText,
CreatePassword,
SMSManager,
TokenManager,
EmailManager,
Documents,
Signatures,
Expand Down Expand Up @@ -324,9 +324,14 @@ export default {
token: this.signPassword,
})
},
async signWithSMSCode(token) {
async signWithTokenCode(token) {
const tokenMethods = ['sms', 'whatsapp', 'signal', 'telegram', 'xmpp']
const activeMethod = tokenMethods.find(method =>
Object.hasOwn(this.signMethodsStore.settings, method)
) || 'sms'

await this.signDocument({
method: 'sms',
method: activeMethod,
token,
})
},
Expand Down Expand Up @@ -395,7 +400,7 @@ export default {
this.showModalAndResetErrors('createSignature')
return
}
if (this.signMethodsStore.needSmsCode()) {
if (this.signMethodsStore.needTokenCode()) {
this.showModalAndResetErrors('sms')
return
}
Expand Down
Loading