Skip to content

Commit

Permalink
Implement frontend to show certificate data
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Mar 12, 2024
1 parent b0ab064 commit 702c0f7
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/helpers/certification.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const options = [
value: '',
helperText: t('libresign', 'Two-letter ISO 3166 country code'),
},
{
id: 'CN',
label: 'Name',
min: 1,
value: '',
helperText: t('libresign', 'Name (CN)'),
},
{
id: 'ST',
label: 'State',
Expand Down
27 changes: 20 additions & 7 deletions src/views/Account/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
<CloudUploadIcon :size="20" />
</template>
</NcButton>
<NcButton v-if="signMethodsStore.hasSignatureFile()"
:wide="true"
@click="handleModal('readCertificate')">
{{ t('libresign', 'Read certificate') }}
<template #icon>
<LockOpenCheckIcon :size="20" />
</template>
</NcButton>
<NcButton v-if="signMethodsStore.hasSignatureFile()"
:wide="true"
@click="deleteCertificate()">
Expand All @@ -30,25 +38,26 @@
</NcButton>
<NcButton v-if="certificateEngine !== 'none' && !signMethodsStore.hasSignatureFile()"
:wide="true"
@click="handleModal(true)">
@click="handleModal('createPassword')">
{{ t('libresign', 'Create certificate') }}
<template #icon>
<CertificateIcon :size="20" />
</template>
</NcButton>
<NcButton v-else-if="signMethodsStore.hasSignatureFile()"
:wide="true"
@click="handleModal(true)">
@click="handleModal('resetPassword')">
{{ t('librsign', 'Change password') }}
<template #icon>
<FileReplaceIcon :size="20" />
</template>
</NcButton>
</div>
<NcModal v-if="modal"
@close="handleModal(false)">
<CreatePassword v-if="!signMethodsStore.hasSignatureFile()" @close="handleModal(false)" />
<ResetPassword v-if="signMethodsStore.hasSignatureFile()" @close="handleModal(false)" />
<NcModal v-if="modal.length > 0"
@close="handleModal('')">
<CreatePassword v-if="modal === 'createPassword'" @close="handleModal('')" />
<ReadCertificate v-if="modal === 'readCertificate'" @close="handleModal('')" />
<ResetPassword v-if="modal === 'resetPassword'" @close="handleModal('')" />
</NcModal>
</div>
</div>
Expand All @@ -72,10 +81,12 @@ import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import CloudUploadIcon from 'vue-material-design-icons/CloudUpload.vue'
import LockOpenCheckIcon from 'vue-material-design-icons/LockOpenCheck.vue'
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
import FileReplaceIcon from 'vue-material-design-icons/FileReplace.vue'
import CertificateIcon from 'vue-material-design-icons/Certificate.vue'
import CreatePassword from '../CreatePassword.vue'
import ReadCertificate from '../ReadCertificate.vue'
import ResetPassword from '../ResetPassword.vue'
import UserImage from './partials/UserImage.vue'
import Signatures from './partials/Signatures.vue'
Expand All @@ -90,10 +101,12 @@ export default {
NcContent,
NcButton,
CloudUploadIcon,
LockOpenCheckIcon,
DeleteIcon,
FileReplaceIcon,
CertificateIcon,
CreatePassword,
ReadCertificate,
ResetPassword,
Signatures,
UserImage,
Expand All @@ -107,7 +120,7 @@ export default {
data() {
return {
user: getCurrentUser(),
modal: false,
modal: '',
certificateEngine: loadState('libresign', 'certificate_engine', ''),
}
},
Expand Down
7 changes: 1 addition & 6 deletions src/views/CreatePassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ export default {
},
data() {
return {
modal: false,
hasLoading: false,
password: '',
hasPfx: false,
}
},
methods: {
Expand All @@ -64,7 +62,7 @@ export default {
.then(() => {
showSuccess(t('libresign', 'New password to sign documents has been created'))
this.signMethodsStore.setHasSignatureFile(true)
this.clear()
this.password = ''
this.$emit('close', true)
this.$emit('password:created', true)
})
Expand All @@ -79,9 +77,6 @@ export default {
})
this.hasLoading = false
},
clear() {
this.password = ''
},
},
}
</script>
Expand Down
199 changes: 199 additions & 0 deletions src/views/ReadCertificate.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<template>
<NcContent app-name="libresign" class="with-sidebar--full">
<form @submit="e => e.preventDefault()">
<header>
<h2>{{ t('libresign', 'Certificate data') }}</h2>
</header>
<table v-if="Object.keys(certificateData).length">
<thead>
<tr>
<th colspan="2">
{{ t('libresign', 'Issuer of certificate') }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="(value, customName) in certificateData.issuer" :key="customName">
<td>{{ getLabelFromId(customName) }}</td>
<td>{{ value }}</td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="2">
{{ t('libresign', 'Owner of certificate') }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="(value, customName) in certificateData.subject" :key="customName">
<td>{{ getLabelFromId(customName) }}</td>
<td>{{ value }}</td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="2">
{{ t('libresign', 'Validate') }}
</th>
</tr>
</thead>
<tbody>
<tr>
<td>From</td>
<td>{{ certificateData.validate.from }}</td>
</tr>
<tr>
<td>To</td>
<td>{{ certificateData.validate.to }}</td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="2">
{{ t('libresign', 'Extra informations') }}
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Info access</td>
<td>{{ certificateData.issuerInfoAccess }}</td>
</tr>
<tr>
<td>Name</td>
<td>{{ certificateData.name }}</td>
</tr>
<tr>
<td>Alt name</td>
<td>{{ certificateData.subjectAltName }}</td>
</tr>
</tbody>
</table>
<div v-else class="container">
<div class="input-group">
<NcPasswordField :disabled="hasLoading"
:label="t('libresign', 'Certificate password')"
:placeholder="t('libresign', 'Certificate password')"
:value.sync="password" />
</div>
<NcButton :disabled="hasLoading" @click="send()">
<template #icon>
<NcLoadingIcon v-if="hasLoading" :size="20" />
</template>
{{ t('libresign', 'Confirm') }}
</NcButton>
</div>
</form>
</NcContent>
</template>

<script>
import '@nextcloud/password-confirmation/dist/style.css' // Required for dialog styles
import NcContent from '@nextcloud/vue/dist/Components/NcContent.js'
import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import { selectCustonOption } from '../helpers/certification.js'
export default {
name: 'ReadCertificate',
components: {
NcContent,
NcPasswordField,
NcButton,
NcLoadingIcon,
},
data() {
return {
hasLoading: false,
password: '',
certificateData: [],
}
},
methods: {
getLabelFromId(id) {
const item = selectCustonOption(id).unwrap()
return item.label
},
async send() {
this.hasLoading = true
await axios.post(generateOcsUrl('/apps/libresign/api/v1/account/pfx/read'), {
password: this.password,
})
.then(({ data }) => {
this.certificateData = data
})
.catch(({ response }) => {
this.signMethodsStore.setHasSignatureFile(false)
if (response.data.message) {
showError(response.data.message)
} else {
showError(t('libresign', 'Error creating new password, please contact the administrator'))
}
})
this.hasLoading = false
},
},
}
</script>

<style lang="scss" scoped>
form{
display: flex;
flex-direction: column;
width: 100%;
max-width: 100%;
justify-content: center;
align-items: center;
text-align: center;
header{
font-weight: bold;
font-size: 20px;
margin-bottom: 12px;
line-height: 30px;
color: var(--color-text-light);
}
}
.container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
gap: 4px 0;
}
.input-group{
justify-content: space-between;
display: flex;
flex-direction: column;
width: 100%;
}
table {
display: block;
width: 100%;
white-space: unset;
}
td {
padding: 5px;
border-bottom: 1px solid var(--color-border);
}
th {
font-weight: bold;
}
tr:last-child td {
border-bottom: none;
}
tr :first-child {
opacity: .5;
}
</style>

0 comments on commit 702c0f7

Please sign in to comment.