PasswordSection.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 :name="t('settings', 'Password')">
  21. <form id="passwordform" method="POST" @submit.prevent="changePassword">
  22. <NcPasswordField id="old-pass"
  23. :label="t('settings', 'Current password')"
  24. name="oldpassword"
  25. :value.sync="oldPass"
  26. autocomplete="current-password"
  27. autocapitalize="none"
  28. spellcheck="false" />
  29. <NcPasswordField id="new-pass"
  30. :label="t('settings', 'New password')"
  31. :value.sync="newPass"
  32. :maxlength="469"
  33. autocomplete="new-password"
  34. autocapitalize="none"
  35. spellcheck="false"
  36. :check-password-strength="true" />
  37. <NcButton type="primary"
  38. native-type="submit"
  39. :disabled="newPass.length === 0 || oldPass.length === 0">
  40. {{ t('settings', 'Change password') }}
  41. </NcButton>
  42. </form>
  43. </NcSettingsSection>
  44. </template>
  45. <script>
  46. import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
  47. import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
  48. import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
  49. import axios from '@nextcloud/axios'
  50. import { generateUrl } from '@nextcloud/router'
  51. import { showSuccess, showError } from '@nextcloud/dialogs'
  52. export default {
  53. name: 'PasswordSection',
  54. components: {
  55. NcSettingsSection,
  56. NcButton,
  57. NcPasswordField,
  58. },
  59. data() {
  60. return {
  61. oldPass: '',
  62. newPass: '',
  63. }
  64. },
  65. methods: {
  66. changePassword() {
  67. axios.post(generateUrl('/settings/personal/changepassword'), {
  68. oldpassword: this.oldPass,
  69. newpassword: this.newPass,
  70. })
  71. .then(res => res.data)
  72. .then(data => {
  73. if (data.status === 'error') {
  74. this.errorMessage = data.data.message
  75. showError(data.data.message)
  76. } else {
  77. showSuccess(data.data.message)
  78. }
  79. })
  80. },
  81. },
  82. }
  83. </script>
  84. <style>
  85. #passwordform {
  86. display: flex;
  87. flex-direction: column;
  88. gap: 1rem;
  89. max-width: 400px;
  90. }
  91. </style>