You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ResetPassword.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!--
  2. - @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. -
  4. - @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. -
  6. - @license GNU AGPL version 3 or any later version
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -->
  21. <template>
  22. <form @submit.prevent="submit">
  23. <p>
  24. <input id="user"
  25. v-model="user"
  26. type="text"
  27. name="user"
  28. :placeholder="t('core', 'Username or email')"
  29. :aria-label="t('core', 'Username or email')"
  30. required
  31. @change="updateUsername">
  32. <!--<?php p($_['user_autofocus'] ? 'autofocus' : ''); ?>
  33. autocomplete="<?php p($_['login_form_autocomplete']); ?>" autocapitalize="none" autocorrect="off"-->
  34. <label for="user" class="infield">{{ t('core', 'Username or email') }}</label>
  35. </p>
  36. <div id="reset-password-wrapper">
  37. <input id="reset-password-submit"
  38. type="submit"
  39. class="login primary"
  40. title=""
  41. :value="t('core', 'Reset password')">
  42. <div class="submit-icon"
  43. :class="{
  44. 'icon-confirm-white': !loading,
  45. 'icon-loading-small': loading && invertedColors,
  46. 'icon-loading-small-dark': loading && !invertedColors,
  47. }" />
  48. </div>
  49. <p v-if="message === 'send-success'"
  50. class="update">
  51. {{ t('core', 'A password reset message has been sent to the e-mail address of this account. If you do not receive it, check your spam/junk folders or ask your local administrator for help.') }}
  52. <br>
  53. {{ t('core', 'If it is not there ask your local administrator.') }}
  54. </p>
  55. <p v-else-if="message === 'send-error'"
  56. class="update warning">
  57. {{ t('core', 'Couldn\'t send reset email. Please contact your administrator.') }}
  58. </p>
  59. <p v-else-if="message === 'reset-error'"
  60. class="update warning">
  61. {{ t('core', 'Password can not be changed. Please contact your administrator.') }}
  62. </p>
  63. <p v-else-if="message"
  64. class="update"
  65. :class="{warning: error}" />
  66. <a href="#"
  67. @click.prevent="$emit('abort')">
  68. {{ t('core', 'Back to login') }}
  69. </a>
  70. </form>
  71. </template>
  72. <script>
  73. import axios from '@nextcloud/axios'
  74. import { generateUrl } from '../../OC/routing'
  75. export default {
  76. name: 'ResetPassword',
  77. props: {
  78. username: {
  79. type: String,
  80. required: true,
  81. },
  82. resetPasswordLink: {
  83. type: String,
  84. required: true,
  85. },
  86. invertedColors: {
  87. type: Boolean,
  88. default: false,
  89. },
  90. },
  91. data() {
  92. return {
  93. error: false,
  94. loading: false,
  95. message: undefined,
  96. user: this.username,
  97. }
  98. },
  99. watch: {
  100. username(value) {
  101. this.user = value
  102. },
  103. },
  104. methods: {
  105. updateUsername() {
  106. this.$emit('update:username', this.user)
  107. },
  108. submit() {
  109. this.loading = true
  110. this.error = false
  111. this.message = ''
  112. const url = generateUrl('/lostpassword/email')
  113. const data = {
  114. user: this.user,
  115. }
  116. return axios.post(url, data)
  117. .then(resp => resp.data)
  118. .then(data => {
  119. if (data.status !== 'success') {
  120. throw new Error(`got status ${data.status}`)
  121. }
  122. this.message = 'send-success'
  123. })
  124. .catch(e => {
  125. console.error('could not send reset e-mail request', e)
  126. this.error = true
  127. this.message = 'send-error'
  128. })
  129. .then(() => { this.loading = false })
  130. },
  131. },
  132. }
  133. </script>
  134. <style scoped>
  135. .update {
  136. width: auto;
  137. }
  138. </style>