index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div class="p-password">
  3. <div v-if="action === 'change'" class="step ptc-inner">
  4. <div class="ptc-form">
  5. <h3 class="title">Change Password</h3>
  6. <div class="ptc-form-item">
  7. <input
  8. v-model="values.new_password"
  9. class="ptc-input"
  10. type="password"
  11. placeholder="Enter new password"
  12. />
  13. </div>
  14. <div class="ptc-form-item">
  15. <input
  16. v-model="values.new_password_confirmation"
  17. class="ptc-input"
  18. type="password"
  19. placeholder="Repeat new password"
  20. />
  21. </div>
  22. <div class="ptc-form-item">
  23. <button class="ptc-button" @click="handleSubmit(applyChange)">
  24. SUBMIT
  25. </button>
  26. </div>
  27. </div>
  28. </div>
  29. <div v-else-if="step === 0" class="step ptc-inner">
  30. <h3 class="title">Recover password</h3>
  31. <div class="desc">
  32. We will send you an email for password reset. Please check it
  33. </div>
  34. <div class="ptc-form">
  35. <div class="ptc-form-item">
  36. <input
  37. v-model="resetForm.email"
  38. class="ptc-input"
  39. placeholder="email address"
  40. />
  41. </div>
  42. <div class="ptc-form-item">
  43. <button class="ptc-button" @click="sendEmail">NEXT</button>
  44. </div>
  45. <div class="ptc-form-item">
  46. <button class="ptc-button ptc-button--stroke" @click="$router.back()">
  47. BACK
  48. </button>
  49. </div>
  50. </div>
  51. </div>
  52. <div v-else-if="step === 1" class="step ptc-inner">
  53. <h3 class="title">Recover password</h3>
  54. <div class="desc">
  55. We will send you an email( {{ resetForm.email }} )The password reset
  56. email has been sent. Please go to check it
  57. </div>
  58. <!-- <div class="ptc-form">
  59. <div class="ptc-form-item">
  60. <button class="ptc-button" @click="next">GO</button>
  61. </div>
  62. </div> -->
  63. </div>
  64. <div v-if="step === 2" class="step ptc-inner">
  65. <h3 class="title">Recover password</h3>
  66. <div class="desc">
  67. Please set a new password for {{ resetForm.email }}. It is recommended
  68. to use a combination of numbers, letters, and characters to improve the
  69. password security level
  70. </div>
  71. <div class="ptc-form">
  72. <div class="ptc-form-item">
  73. <input
  74. v-model="resetForm.password"
  75. class="ptc-input"
  76. placeholder="6-20 digits password, case sensitive"
  77. />
  78. </div>
  79. <div class="ptc-form-item">
  80. <button class="ptc-button" @click="applyReset">SUBMIT</button>
  81. </div>
  82. </div>
  83. </div>
  84. <div v-else-if="step === 3" class="step ptc-inner">
  85. <i class="icon-success"></i>
  86. <h3 class="title tac">Password reset successfully</h3>
  87. <button class="ptc-button mgt96" @click="$router.push('/login')">
  88. TO LOG IN
  89. </button>
  90. </div>
  91. </div>
  92. </template>
  93. <script setup lang="ts">
  94. import { reactive } from 'vue'
  95. import { useRoute, useRouter } from 'vue-router'
  96. import { state } from '@/store'
  97. import {
  98. sendPasswordEmail,
  99. resetPassword,
  100. changePassword,
  101. } from '@/service/user'
  102. import { string } from 'yup'
  103. import { debounce } from 'lodash-es'
  104. import useForm from '@/hooks/useForm'
  105. import Toast from '@/components/toast'
  106. const props = defineProps<{ action: 'change' | 'reset' }>()
  107. const router = useRouter()
  108. const { query } = useRoute() as any
  109. const step = query.step ? +(query.step as string) : 0
  110. const { values, handleSubmit } = useForm<ApiUser.PasswordChange.Request>({
  111. schema: {
  112. new_password: string().required(),
  113. new_password_confirmation: string().required(),
  114. },
  115. })
  116. const resetForm = reactive<ApiUser.PasswordReset.Request>({
  117. email: step === 2 ? query.email : '',
  118. token: query.token || '',
  119. password: '',
  120. password_confirmation: '',
  121. })
  122. state.bgWhite = true
  123. function next() {
  124. router.push({
  125. path: '',
  126. query: { step: step + 1 },
  127. })
  128. }
  129. async function applyChange() {
  130. // await changePassword(values as any)
  131. }
  132. async function sendEmail() {
  133. try {
  134. await string()
  135. .email('invalid email')
  136. .required('email is required')
  137. .validate(resetForm.email)
  138. await sendPasswordEmail(resetForm.email)
  139. next()
  140. } catch (err) {
  141. Toast(err.message)
  142. }
  143. }
  144. async function applyReset() {
  145. try {
  146. await string().required('password is required').validate(resetForm.password)
  147. resetForm.password_confirmation = resetForm.password
  148. await resetPassword(resetForm)
  149. next()
  150. } catch (err) {
  151. Toast(err.message)
  152. }
  153. }
  154. </script>
  155. <style lang="scss">
  156. .p-password {
  157. .step {
  158. margin-top: 98px;
  159. padding: 0 76px;
  160. @include media-breakpoint-up(md) {
  161. min-height: 1084px - 98px;
  162. }
  163. }
  164. .title {
  165. line-height: 56px;
  166. font-size: 40px;
  167. font-weight: 500;
  168. color: #333;
  169. }
  170. .desc {
  171. margin: 36px 0 64px;
  172. line-height: 44px;
  173. font-size: 32px;
  174. color: #333;
  175. }
  176. .icon-success {
  177. display: block;
  178. margin: 0 auto 32px;
  179. @include icon('@img/success.png', 96px);
  180. }
  181. .mgt96 {
  182. margin-top: 96px;
  183. }
  184. }
  185. </style>