|
2 | 2 | - SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors |
3 | 3 | - SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | --> |
5 | | -<template> |
6 | | - <NcSettingsSection :name="t('settings', 'Password')"> |
7 | | - <form id="passwordform" method="POST" @submit.prevent="changePassword"> |
8 | | - <NcPasswordField |
9 | | - id="old-pass" |
10 | | - v-model="oldPass" |
11 | | - :label="t('settings', 'Current password')" |
12 | | - name="oldpassword" |
13 | | - autocomplete="current-password" |
14 | | - autocapitalize="none" |
15 | | - spellcheck="false" /> |
16 | | - |
17 | | - <NcPasswordField |
18 | | - id="new-pass" |
19 | | - v-model="newPass" |
20 | | - :label="t('settings', 'New password')" |
21 | | - :maxlength="469" |
22 | | - autocomplete="new-password" |
23 | | - autocapitalize="none" |
24 | | - spellcheck="false" |
25 | | - :check-password-strength="true" /> |
26 | | - |
27 | | - <NcButton |
28 | | - variant="primary" |
29 | | - type="submit" |
30 | | - :disabled="newPass.length === 0 || oldPass.length === 0"> |
31 | | - {{ t('settings', 'Change password') }} |
32 | | - </NcButton> |
33 | | - </form> |
34 | | - </NcSettingsSection> |
35 | | -</template> |
36 | 5 |
|
37 | | -<script> |
| 6 | +<script setup lang="ts"> |
38 | 7 | import axios from '@nextcloud/axios' |
39 | 8 | import { showError, showSuccess } from '@nextcloud/dialogs' |
| 9 | +import { t } from '@nextcloud/l10n' |
40 | 10 | import { generateUrl } from '@nextcloud/router' |
| 11 | +import { NcFormBox } from '@nextcloud/vue' |
| 12 | +import { ref } from 'vue' |
41 | 13 | import NcButton from '@nextcloud/vue/components/NcButton' |
42 | 14 | import NcPasswordField from '@nextcloud/vue/components/NcPasswordField' |
43 | 15 | import NcSettingsSection from '@nextcloud/vue/components/NcSettingsSection' |
44 | 16 |
|
45 | | -export default { |
46 | | - name: 'PasswordSection', |
47 | | - components: { |
48 | | - NcSettingsSection, |
49 | | - NcButton, |
50 | | - NcPasswordField, |
51 | | - }, |
| 17 | +const passwordform = ref<HTMLFormElement>() |
52 | 18 |
|
53 | | - data() { |
54 | | - return { |
55 | | - oldPass: '', |
56 | | - newPass: '', |
57 | | - } |
58 | | - }, |
| 19 | +const oldPass = ref('') |
| 20 | +const newPass = ref('') |
59 | 21 |
|
60 | | - methods: { |
61 | | - changePassword() { |
62 | | - axios.post(generateUrl('/settings/personal/changepassword'), { |
63 | | - oldpassword: this.oldPass, |
64 | | - newpassword: this.newPass, |
65 | | - }) |
66 | | - .then((res) => res.data) |
67 | | - .then((data) => { |
68 | | - if (data.status === 'error') { |
69 | | - this.errorMessage = data.data.message |
70 | | - showError(data.data.message) |
71 | | - } else { |
72 | | - showSuccess(data.data.message) |
73 | | - } |
74 | | - }) |
75 | | - }, |
76 | | - }, |
| 22 | +/** |
| 23 | + * Change the user's password |
| 24 | + */ |
| 25 | +async function changePassword() { |
| 26 | + const { data } = await axios.post(generateUrl('/settings/personal/changepassword'), { |
| 27 | + oldpassword: oldPass.value, |
| 28 | + newpassword: newPass.value, |
| 29 | + }) |
| 30 | + if (data.status === 'error') { |
| 31 | + showError(data.data.message) |
| 32 | + } else { |
| 33 | + showSuccess(data.data.message) |
| 34 | + oldPass.value = '' |
| 35 | + newPass.value = '' |
| 36 | + passwordform.value?.reset() |
| 37 | + } |
77 | 38 | } |
78 | 39 | </script> |
79 | 40 |
|
80 | | -<style> |
81 | | - #passwordform { |
82 | | - display: flex; |
83 | | - flex-direction: column; |
84 | | - gap: 1rem; |
85 | | - max-width: 400px; |
86 | | - } |
| 41 | +<template> |
| 42 | + <NcSettingsSection :name="t('settings', 'Password')"> |
| 43 | + <form |
| 44 | + ref="passwordform" |
| 45 | + :class="$style.passwordSection__form" |
| 46 | + @submit.prevent="changePassword"> |
| 47 | + <NcFormBox> |
| 48 | + <NcPasswordField |
| 49 | + v-model="oldPass" |
| 50 | + :label="t('settings', 'Current password')" |
| 51 | + name="oldpassword" |
| 52 | + autocomplete="current-password" |
| 53 | + autocapitalize="none" |
| 54 | + required |
| 55 | + spellcheck="false" /> |
| 56 | + |
| 57 | + <NcPasswordField |
| 58 | + v-model="newPass" |
| 59 | + check-password-strength |
| 60 | + :label="t('settings', 'New password')" |
| 61 | + :maxlength="469" |
| 62 | + name="newpassword" |
| 63 | + autocomplete="new-password" |
| 64 | + autocapitalize="none" |
| 65 | + required |
| 66 | + spellcheck="false" /> |
| 67 | + </NcFormBox> |
| 68 | + |
| 69 | + <NcButton |
| 70 | + type="submit" |
| 71 | + variant="primary" |
| 72 | + wide> |
| 73 | + {{ t('settings', 'Change password') }} |
| 74 | + </NcButton> |
| 75 | + </form> |
| 76 | + </NcSettingsSection> |
| 77 | +</template> |
| 78 | + |
| 79 | +<style module> |
| 80 | +.passwordSection__form { |
| 81 | + display: flex; |
| 82 | + flex-direction: column; |
| 83 | + gap: calc(2 * var(--default-grid-baseline)); |
| 84 | + max-width: 300px !important; |
| 85 | +} |
87 | 86 | </style> |
0 commit comments