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.

255 lines
7.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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="getPath == null">
  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="Email"
  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="getPath != null && resetSuccess == false">
  46. <p class="title">{{ $t("Reset Password") }}</p>
  47. <v-form v-model="resetValid">
  48. <v-text-field
  49. v-model="userData.Password"
  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. :class="[
  87. '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 tw-text-white tw-bg-primary-default tw-border-primary-default']"
  88. >
  89. {{ $t("Reset Password") }}
  90. </button>
  91. </div>
  92. </div>
  93. <div v-if="resetSuccess">
  94. <p class="title">{{ $t("Password Reset") }}</p>
  95. <p class="neutrals--text text--darken-5 text-size-14">
  96. {{ $t("Congrats! Your password has been successfully reset") }}
  97. </p>
  98. <nuxt-link :to="localePath('/')">
  99. <v-btn
  100. @click="redirectHome"
  101. width="100%"
  102. color="primary"
  103. class="border-radius-16 mt-4"
  104. >
  105. <span class="text-capitalize">{{ $t("Explore with ShowEasy") }}</span>
  106. </v-btn>
  107. </nuxt-link>
  108. <v-spacer class="d-flex justify-center mt-5">
  109. <span
  110. class="text-size-12 primary--text"
  111. v-html="$t('Go to ShowEasy in sec', { second: this.countdown })"
  112. ></span>
  113. </v-spacer>
  114. </div>
  115. </div>
  116. </template>
  117. <script>
  118. export default {
  119. name: "Forgot",
  120. layout: "login",
  121. auth: false,
  122. data() {
  123. return {
  124. showPass: false,
  125. showConfirmPass: false,
  126. resendValid: false,
  127. resetValid: false,
  128. disableBtn: false,
  129. resetSuccess: false,
  130. countdown: 60,
  131. Email: "",
  132. userConfirmPass: "",
  133. userData: {
  134. //user_id: "",
  135. //auth_code: "",
  136. Password: "",
  137. },
  138. result: "",
  139. getPath: null,
  140. rules: {
  141. require: (value) => !!value || this.$t("Required."),
  142. email: (v) =>
  143. /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(
  144. v
  145. ) || this.$t("Invalid email"),
  146. checkPassword: (v) =>
  147. (/(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/.test(v) &&
  148. v.length >= 8 &&
  149. v.length <= 20) ||
  150. this.$t(
  151. "Passwords must be 8-20 characters with at least 1 number, 1 lower case letter and 1 upper case letter"
  152. ),
  153. confirmPass: (v) =>
  154. v === this.userData.Password ||
  155. this.$t("Your password and confirmation password do not match"),
  156. },
  157. };
  158. },
  159. created(){
  160. this.$auth.$storage.removeUniversal('userPassword');
  161. this.$auth.$storage.removeUniversal('userAccount');
  162. this.getPAth();
  163. },
  164. methods: {
  165. getPAth(){
  166. let vm = this;
  167. if (this.$route.query.Email) {
  168. vm.getPath = vm.$route.query.Email;
  169. }else{
  170. vm.getPath = null;
  171. }
  172. },
  173. sendForgotMail() {
  174. this.$axios
  175. .post(`/trending/api/Signup/SendForgotMail?Email=${this.Email}`)
  176. .then((response) => {
  177. //console.log(JSON.stringify(response));
  178. if(response.data.STATUSCODE == "404"){
  179. //console.log("此帳號未認證或已註銷");
  180. this.resendValid = false;
  181. }
  182. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  183. let data = response.data.DATA.rel
  184. if(data){
  185. this.result = data;
  186. this.disableBtn = !this.disableBtn;
  187. this.timeout = setInterval(() => {
  188. if (this.countdown > 0) {
  189. this.countdown--;
  190. }
  191. if (this.countdown === 0) {
  192. this.disableBtn = !this.disableBtn;
  193. this.countdown = 60;
  194. clearInterval(this.timeout);
  195. }
  196. }, 1000);
  197. }
  198. }
  199. })
  200. .catch((error) => {
  201. console.log(error);
  202. });
  203. },
  204. resetUserPass() {
  205. if (
  206. this.userData.Password === this.userConfirmPass &&
  207. this.resetValid
  208. ) {
  209. //this.userData.user_id = this.$route.query.user_uuid;
  210. //this.userData.auth_code = this.$route.query.auth_code;
  211. this.$axios
  212. .post(`/trending/api/Signup/ResetPassword?Email=${this.getPath}&Password=${this.userData.Password}`)
  213. .then((response) => {
  214. //console.log(JSON.stringify(response));
  215. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  216. let data = response.data.DATA.rel
  217. if(data){
  218. this.resetSuccess = !this.resetSuccess;
  219. this.countdown = 3;
  220. this.timer = setInterval(() => {
  221. if (this.countdown > 0) {
  222. this.countdown--;
  223. } else {
  224. clearInterval(this.timer);
  225. this.$router.push(this.localePath("/"));
  226. }
  227. }, 1000);
  228. }
  229. }
  230. })
  231. .catch((error) => {
  232. console.log(error);
  233. });
  234. }
  235. },
  236. },
  237. beforeUnmount() {
  238. clearInterval(this.timeout);
  239. clearInterval(this.timer);
  240. },
  241. };
  242. </script>
  243. <style scoped>
  244. .title {
  245. font-weight: 700;
  246. font-size: 26px;
  247. line-height: 34px;
  248. letter-spacing: 0.02em;
  249. color: #232323;
  250. }
  251. </style>