index.vue 5.5 KB

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