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.

225 lines
7.0 KiB

2 years ago
  1. <template>
  2. <div
  3. class="tw-bg-white md:tw-rounded-[24px] md:tw-mt-[30px] md:tw-pt-[60px] md:tw-pb-[150px] md:tw-px-[30px]"
  4. >
  5. <div v-if="Object.keys($route.query).length < 2">
  6. <p class="tw-text-[26px] tw-font-bold tw-mb-[20px] md:tw-text-[18px]">
  7. {{ $t("Forgot Password") }}
  8. </p>
  9. <p class="tw-body-3 tw-text-black tw-mb-[24px]">
  10. {{
  11. $t(
  12. "Dont worry! It happens. Please enter the address associated with your account."
  13. )
  14. }}
  15. </p>
  16. <v-form v-model="resendValid">
  17. <v-text-field
  18. v-model="user_mail"
  19. background-color="neutrals darken-1"
  20. :label="this.$t('Email')"
  21. placeholder=""
  22. filled
  23. rounded
  24. dense
  25. single-line
  26. :rules="[rules.email, rules.require]"
  27. ></v-text-field>
  28. </v-form>
  29. <div class="md:tw-flex md:tw-justify-center md:tw-items-center">
  30. <button
  31. @click="sendForgotMail"
  32. :disabled="!resendValid"
  33. :class="[
  34. 'tw-block tw-w-full tw-py-[10px] tw-rounded-[16px] tw-border tw-border-solid tw-body-3 tw-font-normal tw-transition-all tw-duration-200 tw-ease-in-out',
  35. resendValid
  36. ? 'tw-text-white tw-bg-primary-default tw-border-primary-default'
  37. : 'tw-text-base-disable tw-bg-neutral-100 tw-border-neutral-100',
  38. ]"
  39. >
  40. {{ $t("Reset Password")
  41. }}<span v-if="disableBtn">({{ this.countdown }})</span>
  42. </button>
  43. </div>
  44. </div>
  45. <div v-if="Object.keys($route.query).length >= 2 && !resetSuccess">
  46. <p class="title">{{ $t("Reset Password") }}</p>
  47. <v-form v-model="resetValid">
  48. <v-text-field
  49. v-model="userData.user_new_pass"
  50. background-color="neutrals darken-1"
  51. :label="this.$t('Password') + '*'"
  52. :type="showPass ? 'text' : 'password'"
  53. placeholder=""
  54. filled
  55. rounded
  56. dense
  57. single-line
  58. persistent-hint
  59. :rules="[rules.checkPassword, rules.require]"
  60. :hint="
  61. this.$t(
  62. 'Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter'
  63. )
  64. "
  65. :append-icon="showPass ? 'mdi-eye' : 'mdi-eye-off'"
  66. @click:append="showPass = !showPass"
  67. ></v-text-field>
  68. <v-text-field
  69. v-model="userConfirmPass"
  70. background-color="neutrals darken-1"
  71. :label="this.$t('Confirm Password') + '*'"
  72. :type="showConfirmPass ? 'text' : 'password'"
  73. placeholder=""
  74. filled
  75. rounded
  76. dense
  77. single-line
  78. :rules="[rules.checkPassword, rules.require, rules.confirmPass]"
  79. :append-icon="showConfirmPass ? 'mdi-eye' : 'mdi-eye-off'"
  80. @click:append="showConfirmPass = !showConfirmPass"
  81. ></v-text-field>
  82. </v-form>
  83. <div class="md:tw-flex md:tw-justify-center md:tw-items-center">
  84. <button
  85. @click="resetUserPass"
  86. :disabled="!resetValid"
  87. :class="[
  88. 'tw-block tw-w-full tw-py-[10px] tw-rounded-[16px] tw-border tw-border-solid tw-body-3 tw-font-normal tw-transition-all tw-duration-200 tw-ease-in-out',
  89. resendValid
  90. ? 'tw-text-white tw-bg-primary-default tw-border-primary-default'
  91. : 'tw-text-base-disable tw-bg-neutral-100 tw-border-neutral-100',
  92. ]"
  93. >
  94. {{ $t("Reset Password") }}
  95. </button>
  96. </div>
  97. </div>
  98. <div v-if="resetSuccess">
  99. <p class="title">{{ $t("Password Reset") }}</p>
  100. <p class="neutrals--text text--darken-5 text-size-14">
  101. {{ $t("Congrats! Your password has been successfully reset") }}
  102. </p>
  103. <nuxt-link :to="localePath('/')">
  104. <v-btn
  105. @click="redirectHome"
  106. width="100%"
  107. color="primary"
  108. class="border-radius-16 mt-4"
  109. >
  110. <span class="text-capitalize">{{ $t("Explore with ShowEasy") }}</span>
  111. </v-btn>
  112. </nuxt-link>
  113. <v-spacer class="d-flex justify-center mt-5">
  114. <span
  115. class="text-size-12 primary--text"
  116. v-html="$t('Go to ShowEasy in sec', { second: this.countdown })"
  117. ></span>
  118. </v-spacer>
  119. </div>
  120. </div>
  121. </template>
  122. <script>
  123. export default {
  124. name: "Forgot",
  125. layout: "login",
  126. auth: false,
  127. data() {
  128. return {
  129. showPass: false,
  130. showConfirmPass: false,
  131. resendValid: false,
  132. resetValid: false,
  133. disableBtn: false,
  134. resetSuccess: false,
  135. countdown: 60,
  136. user_mail: "",
  137. userConfirmPass: "",
  138. userData: {
  139. user_id: "",
  140. auth_code: "",
  141. user_new_pass: "",
  142. },
  143. rules: {
  144. require: (value) => !!value || this.$t("Required."),
  145. email: (v) =>
  146. /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(
  147. v
  148. ) || this.$t("Invalid email"),
  149. checkPassword: (v) =>
  150. (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) &&
  151. v.length >= 8 &&
  152. v.length <= 20) ||
  153. this.$t(
  154. "Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter"
  155. ),
  156. confirmPass: (v) =>
  157. v === this.userData.user_new_pass ||
  158. this.$t("Your password and confirmation password do not match"),
  159. },
  160. };
  161. },
  162. methods: {
  163. sendForgotMail() {
  164. this.disableBtn = !this.disableBtn;
  165. this.timeout = setInterval(() => {
  166. if (this.countdown > 0) {
  167. this.countdown--;
  168. }
  169. if (this.countdown === 0) {
  170. this.disableBtn = !this.disableBtn;
  171. this.countdown = 60;
  172. clearInterval(this.timeout);
  173. }
  174. }, 1000);
  175. this.$axios
  176. .get(`/member/users/forgot/${this.user_mail}?lang=${this.$i18n.locale}`)
  177. .then((result) => {})
  178. .catch((err) => {
  179. console.log(err);
  180. });
  181. },
  182. resetUserPass() {
  183. if (
  184. this.userData.user_new_pass === this.userConfirmPass &&
  185. this.resetValid
  186. ) {
  187. this.userData.user_id = this.$route.query.user_uuid;
  188. this.userData.auth_code = this.$route.query.auth_code;
  189. this.$axios
  190. .post(`/member/users/reset/?lang=${this.$i18n.locale}`, this.userData)
  191. .then((result) => {
  192. this.resetSuccess = !this.resetSuccess;
  193. this.countdown = 5;
  194. this.timer = setInterval(() => {
  195. if (this.countdown > 0) {
  196. this.countdown--;
  197. } else {
  198. clearInterval(this.timer);
  199. this.$router.push(this.localePath("/"));
  200. }
  201. }, 1000);
  202. })
  203. .catch((err) => {
  204. console.log(err);
  205. });
  206. }
  207. },
  208. },
  209. beforeUnmount() {
  210. clearInterval(this.timeout);
  211. clearInterval(this.timer);
  212. },
  213. };
  214. </script>
  215. <style scoped>
  216. .title {
  217. font-weight: 700;
  218. font-size: 26px;
  219. line-height: 34px;
  220. letter-spacing: 0.02em;
  221. color: #232323;
  222. }
  223. </style>