|
| 1 | +<!-- |
| 2 | + - @copyright 2022 Carl Schwan <carl@carlschwan.eu> |
| 3 | + - |
| 4 | + - @license GNU AGPL version 3 or any later version |
| 5 | + - |
| 6 | + - This program is free software: you can redistribute it and/or modify |
| 7 | + - it under the terms of the GNU Affero General Public License as |
| 8 | + - published by the Free Software Foundation, either version 3 of the |
| 9 | + - License, or (at your option) any later version. |
| 10 | + - |
| 11 | + - This program is distributed in the hope that it will be useful, |
| 12 | + - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + - GNU Affero General Public License for more details. |
| 15 | + - |
| 16 | + - You should have received a copy of the GNU Affero General Public License |
| 17 | + - along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + --> |
| 19 | +<template> |
| 20 | + <NcSettingsSection :title="t('settings', 'Password')"> |
| 21 | + <form id="passwordform" method="POST" @submit.prevent="changePassword"> |
| 22 | + <NcPasswordField id="old-pass" |
| 23 | + :label="t('settings', 'Current password')" |
| 24 | + :label-visible="true" |
| 25 | + name="oldpassword" |
| 26 | + :value.sync="oldPass" |
| 27 | + autocomplete="current-password" |
| 28 | + autocapitalize="none" |
| 29 | + autocorrect="off" /> |
| 30 | + |
| 31 | + <NcPasswordField id="new-pass" |
| 32 | + :label="t('settings', 'New password')" |
| 33 | + :label-visible="true" |
| 34 | + :value.sync="newPass" |
| 35 | + :maxlength="469" |
| 36 | + autocomplete="new-password" |
| 37 | + :check-password-strength="true" |
| 38 | + autocapitalize="none" |
| 39 | + autocorrect="off" |
| 40 | + :check-password-strength="true" /> |
| 41 | + |
| 42 | + <NcButton type="primary" |
| 43 | + native-type="submit" |
| 44 | + :disabled="newPass.length === 0 || oldPass.length === 0"> |
| 45 | + {{ t('settings', 'Change password') }} |
| 46 | + </NcButton> |
| 47 | + </form> |
| 48 | + </NcSettingsSection> |
| 49 | +</template> |
| 50 | + |
| 51 | +<script> |
| 52 | +import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js' |
| 53 | +import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' |
| 54 | +import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js' |
| 55 | +import axios from '@nextcloud/axios' |
| 56 | +import { generateUrl } from '@nextcloud/router' |
| 57 | +import { showSuccess, showError } from '@nextcloud/dialogs' |
| 58 | +
|
| 59 | +export default { |
| 60 | + name: 'PasswordSection', |
| 61 | + components: { |
| 62 | + NcSettingsSection, |
| 63 | + NcButton, |
| 64 | + NcPasswordField, |
| 65 | + }, |
| 66 | + data() { |
| 67 | + return { |
| 68 | + oldPass: '', |
| 69 | + newPass: '', |
| 70 | + } |
| 71 | + }, |
| 72 | + methods: { |
| 73 | + changePassword() { |
| 74 | + axios.post(generateUrl('/settings/personal/changepassword'), { |
| 75 | + oldpassword: this.oldPass, |
| 76 | + newpassword: this.newPass, |
| 77 | + }) |
| 78 | + .then(res => res.data) |
| 79 | + .then(data => { |
| 80 | + if (data.status === 'error') { |
| 81 | + this.errorMessage = data.data.message |
| 82 | + showError(data.data.message) |
| 83 | + } else { |
| 84 | + showSuccess(data.data.message) |
| 85 | + } |
| 86 | + }) |
| 87 | + }, |
| 88 | + }, |
| 89 | +} |
| 90 | +</script> |
| 91 | + |
| 92 | +<style> |
| 93 | + #passwordform { |
| 94 | + display: flex; |
| 95 | + flex-direction: column; |
| 96 | + gap: 1rem; |
| 97 | + max-width: 400px; |
| 98 | + } |
| 99 | +</style> |
0 commit comments