ResetPassword.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. <fieldset>
  24. <p>
  25. <input id="user"
  26. v-model="user"
  27. type="text"
  28. name="user"
  29. autocapitalize="off"
  30. :placeholder="t('core', 'Username or email')"
  31. :aria-label="t('core', 'Username or email')"
  32. required
  33. @change="updateUsername">
  34. <!--<?php p($_['user_autofocus'] ? 'autofocus' : ''); ?>
  35. autocomplete="<?php p($_['login_form_autocomplete']); ?>" autocapitalize="none" autocorrect="off"-->
  36. <label for="user" class="infield">{{ t('core', 'Username or email') }}</label>
  37. </p>
  38. <div id="reset-password-wrapper">
  39. <input id="reset-password-submit"
  40. type="submit"
  41. class="login primary"
  42. title=""
  43. :value="t('core', 'Reset password')">
  44. <div class="submit-icon"
  45. :class="{
  46. 'icon-confirm-white': !loading,
  47. 'icon-loading-small': loading && invertedColors,
  48. 'icon-loading-small-dark': loading && !invertedColors,
  49. }" />
  50. </div>
  51. <p v-if="message === 'send-success'"
  52. class="update">
  53. {{ 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.') }}
  54. <br>
  55. {{ t('core', 'If it is not there ask your local administrator.') }}
  56. </p>
  57. <p v-else-if="message === 'send-error'"
  58. class="update warning">
  59. {{ t('core', 'Couldn\'t send reset email. Please contact your administrator.') }}
  60. </p>
  61. <p v-else-if="message === 'reset-error'"
  62. class="update warning">
  63. {{ t('core', 'Password can not be changed. Please contact your administrator.') }}
  64. </p>
  65. <p v-else-if="message"
  66. class="update"
  67. :class="{warning: error}" />
  68. <a href="#"
  69. @click.prevent="$emit('abort')">
  70. {{ t('core', 'Back to login') }}
  71. </a>
  72. </fieldset>
  73. </form>
  74. </template>
  75. <script>
  76. import axios from '@nextcloud/axios'
  77. import { generateUrl } from '@nextcloud/router'
  78. export default {
  79. name: 'ResetPassword',
  80. props: {
  81. username: {
  82. type: String,
  83. required: true,
  84. },
  85. resetPasswordLink: {
  86. type: String,
  87. required: true,
  88. },
  89. invertedColors: {
  90. type: Boolean,
  91. default: false,
  92. },
  93. },
  94. data() {
  95. return {
  96. error: false,
  97. loading: false,
  98. message: undefined,
  99. user: this.username,
  100. }
  101. },
  102. watch: {
  103. username(value) {
  104. this.user = value
  105. },
  106. },
  107. methods: {
  108. updateUsername() {
  109. this.$emit('update:username', this.user)
  110. },
  111. submit() {
  112. this.loading = true
  113. this.error = false
  114. this.message = ''
  115. const url = generateUrl('/lostpassword/email')
  116. const data = {
  117. user: this.user,
  118. }
  119. return axios.post(url, data)
  120. .then(resp => resp.data)
  121. .then(data => {
  122. if (data.status !== 'success') {
  123. throw new Error(`got status ${data.status}`)
  124. }
  125. this.message = 'send-success'
  126. })
  127. .catch(e => {
  128. console.error('could not send reset e-mail request', e)
  129. this.error = true
  130. this.message = 'send-error'
  131. })
  132. .then(() => { this.loading = false })
  133. },
  134. },
  135. }
  136. </script>
  137. <style scoped>
  138. .update {
  139. width: auto;
  140. }
  141. </style>