-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: able to change password when sign
Signed-off-by: Vitor Mattos <[email protected]>
- Loading branch information
1 parent
156b343
commit c3eacd0
Showing
7 changed files
with
346 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<template> | ||
<div class="user-display-password"> | ||
<NcButton :wide="true" | ||
@click="uploadCertificate()"> | ||
{{ t('libresign', 'Upload certificate') }} | ||
<template #icon> | ||
<CloudUploadIcon :size="20" /> | ||
</template> | ||
</NcButton> | ||
<NcButton v-if="signMethodsStore.hasSignatureFile()" | ||
:wide="true" | ||
@click="signMethodsStore.showModal('readCertificate')"> | ||
{{ t('libresign', 'Read certificate') }} | ||
<template #icon> | ||
<LockOpenCheckIcon :size="20" /> | ||
</template> | ||
</NcButton> | ||
<NcButton v-if="signMethodsStore.hasSignatureFile()" | ||
:wide="true" | ||
@click="deleteCertificate()"> | ||
{{ t('libresign', 'Delete certificate') }} | ||
<template #icon> | ||
<DeleteIcon :size="20" /> | ||
</template> | ||
</NcButton> | ||
<NcButton v-if="certificateEngine !== 'none' && !signMethodsStore.hasSignatureFile()" | ||
:wide="true" | ||
@click="signMethodsStore.showModal('createPassword')"> | ||
{{ t('libresign', 'Create certificate') }} | ||
<template #icon> | ||
<CertificateIcon :size="20" /> | ||
</template> | ||
</NcButton> | ||
<NcButton v-else-if="signMethodsStore.hasSignatureFile()" | ||
:wide="true" | ||
@click="signMethodsStore.showModal('resetPassword')"> | ||
{{ t('librsign', 'Change password') }} | ||
<template #icon> | ||
<FileReplaceIcon :size="20" /> | ||
</template> | ||
</NcButton> | ||
<CreatePassword /> | ||
<ReadCertificate /> | ||
<ResetPassword /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { generateOcsUrl } from '@nextcloud/router' | ||
import { loadState } from '@nextcloud/initial-state' | ||
import { showError, showSuccess } from '@nextcloud/dialogs' | ||
import axios from '@nextcloud/axios' | ||
import CertificateIcon from 'vue-material-design-icons/Certificate.vue' | ||
import CloudUploadIcon from 'vue-material-design-icons/CloudUpload.vue' | ||
import DeleteIcon from 'vue-material-design-icons/Delete.vue' | ||
import FileReplaceIcon from 'vue-material-design-icons/FileReplace.vue' | ||
import LockOpenCheckIcon from 'vue-material-design-icons/LockOpenCheck.vue' | ||
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' | ||
import CreatePassword from '../../CreatePassword.vue' | ||
import ReadCertificate from '../../ReadCertificate.vue' | ||
import ResetPassword from '../../ResetPassword.vue' | ||
import { useSignMethodsStore } from '../../../store/signMethods.js' | ||
export default { | ||
name: 'ManagePassword', | ||
components: { | ||
CertificateIcon, | ||
CloudUploadIcon, | ||
DeleteIcon, | ||
FileReplaceIcon, | ||
LockOpenCheckIcon, | ||
NcButton, | ||
CreatePassword, | ||
ReadCertificate, | ||
ResetPassword, | ||
}, | ||
setup() { | ||
const signMethodsStore = useSignMethodsStore() | ||
return { signMethodsStore } | ||
}, | ||
data() { | ||
return { | ||
modal: '', | ||
certificateEngine: loadState('libresign', 'certificate_engine', ''), | ||
} | ||
}, | ||
methods: { | ||
uploadCertificate() { | ||
const input = document.createElement('input') | ||
// @todo PFX file, didn't worked, wrong code | ||
input.accept = 'application/x-pkcs12' | ||
input.type = 'file' | ||
input.onchange = async (ev) => { | ||
const file = ev.target.files[0] | ||
if (file) { | ||
this.doUpload(file) | ||
} | ||
input.remove() | ||
} | ||
input.click() | ||
}, | ||
async doUpload(file) { | ||
try { | ||
const formData = new FormData() | ||
formData.append('file', file) | ||
const response = await axios.post(generateOcsUrl('/apps/libresign/api/v1/account/pfx'), formData) | ||
showSuccess(response.data.message) | ||
this.signMethodsStore.setHasSignatureFile(true) | ||
} catch (err) { | ||
showError(err.response.data.message) | ||
} | ||
}, | ||
async deleteCertificate() { | ||
const response = await axios.delete(generateOcsUrl('/apps/libresign/api/v1/account/pfx')) | ||
showSuccess(response.data.message) | ||
this.signMethodsStore.setHasSignatureFile(false) | ||
}, | ||
}, | ||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
.user-display-password { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 12px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.