ForgetStep.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <div>
  3. <q-banner class="banner">
  4. {{ bannerMessage }}
  5. </q-banner>
  6. <template v-if="registerStep === 'getUsername'">
  7. <label for="username">
  8. ایمیل یا شماره تلفن همراه
  9. </label>
  10. <q-input id="username"
  11. v-model="username"
  12. outlined
  13. class="username-input"
  14. placeholder="ایمیل یا شماره تلفن همراه"
  15. :disable="loading"
  16. :loading="loading"
  17. @keydown.enter="goToVerifyStep">
  18. <template v-slot:prepend>
  19. <q-icon name="person" />
  20. </template>
  21. </q-input>
  22. <q-btn class="full-width btn-GoToVerify"
  23. color="primary"
  24. label="ارسال کد بازیابی"
  25. :disable="loading"
  26. :loading="loading"
  27. @click="goToVerifyStep" />
  28. <div class="go-to-login-message">
  29. گذرواژه را به خاطر دارید؟
  30. <span class="btn-go-to-login-span"
  31. @click="goToLoginStep">
  32. وارد شوید
  33. </span>
  34. </div>
  35. </template>
  36. <template v-else-if="registerStep === 'verify'">
  37. <label for="verifyNumber">
  38. .لطفا کد تایید ارسال شده به
  39. {{ username }}
  40. را وارد کنید
  41. </label>
  42. <q-input id="verifyNumber"
  43. v-model="verifyNumber"
  44. outlined
  45. class="username-input"
  46. label=""
  47. :disable="loading"
  48. :loading="loading" />
  49. <div class="resend-timer-message">
  50. <template v-if="!timerEnded">
  51. <span class="resend-timer-message-value">
  52. <timer ref="timer"
  53. :time="120"
  54. @stop="onStopTimer" />
  55. </span>
  56. تا درخواست مجدد
  57. </template>
  58. <template v-else>
  59. <q-btn color="primary"
  60. class="full-width"
  61. :loading="sendOtpLoading"
  62. @click="restartTimer">
  63. ارسال مجدد کد تایید
  64. </q-btn>
  65. </template>
  66. </div>
  67. <label class="password-label"
  68. for="password">
  69. گذرواژه
  70. </label>
  71. <q-input id="password"
  72. v-model="password"
  73. outlined
  74. class="password-input"
  75. :type="visibilityIcon === 'visibility' ? 'password' : 'text'"
  76. placeholder="گذرواژه جدید خود را وارد کنید"
  77. @keydown.enter="verify">
  78. <template v-slot:prepend>
  79. <q-icon name="lock_open" />
  80. </template>
  81. <template v-slot:append>
  82. <q-icon :name="visibilityIcon"
  83. class="cursor-pointer"
  84. @click="toggleVisibilityIcon" />
  85. </template>
  86. </q-input>
  87. <q-btn class="full-width btn-verifyUsername"
  88. color="primary"
  89. label="تایید و ورود"
  90. :disable="loading"
  91. :loading="loading"
  92. @click="verify" />
  93. <div class="go-to-set-username-message"
  94. @click="goToGetUsernameStep">
  95. تغییر شماره تلفن همراه یا استفاده از آدرس ایمیل
  96. </div>
  97. </template>
  98. <template v-else-if="registerStep === 'newPassword'">
  99. <q-btn class="full-width btn-login"
  100. color="primary"
  101. label="تایید و ورود"
  102. @click="setNewPassword" />
  103. </template>
  104. </div>
  105. </template>
  106. <script>
  107. import API_ADDRESS from 'src/api/Addresses.js'
  108. import { mixinAuth } from 'src/mixin/Mixins.js'
  109. import Timer from 'src/components/Auth/Timer.vue'
  110. import { APIGateway } from 'src/api/APIGateway.js'
  111. export default {
  112. name: 'ForgetStep',
  113. components: { Timer },
  114. mixins: [mixinAuth],
  115. props: {
  116. redirect: {
  117. type: Boolean,
  118. default: false
  119. }
  120. },
  121. data: () => ({
  122. sendOtpLoading: false,
  123. timerEnded: false,
  124. loading: false,
  125. visibilityIcon: 'visibility',
  126. bannerMessage: 'بازیابی گذرواژه',
  127. registerStep: 'getUsername',
  128. username: null,
  129. verifyNumber: null,
  130. firstname: null,
  131. lastname: null,
  132. password: null,
  133. otpInterval: null,
  134. otpTimer: 120,
  135. userLogin: false,
  136. loadingList: false,
  137. otpStep: 'sendOtp',
  138. otp: null
  139. }),
  140. computed: {
  141. user () {
  142. return this.$store.getters['Auth/user']
  143. },
  144. formatedTimer () {
  145. const second = this.otpTimer % 60
  146. const minute = Math.floor(this.otpTimer / 60)
  147. return minute + ':' + second
  148. }
  149. },
  150. created () {
  151. // if (this.getToken()) {
  152. // this.getUserData(() => { this.redirectTo() })
  153. // }
  154. this.setRegisterStep('getUsername')
  155. this.$store.dispatch('Auth/logOut')
  156. },
  157. methods: {
  158. toggleVisibilityIcon () {
  159. this.visibilityIcon = this.visibilityIcon === 'visibility' ? 'visibility_off' : 'visibility'
  160. },
  161. onStopTimer () {
  162. this.timerEnded = true
  163. },
  164. restartTimer () {
  165. this.sendOtpForgotPassword()
  166. },
  167. sendOtpForgotPassword () {
  168. this.sendOtpLoading = true
  169. APIGateway.auth.sendOtpForgotPassword({
  170. input: this.username
  171. })
  172. .then(() => {
  173. this.sendOtpLoading = false
  174. this.timerEnded = false
  175. this.$nextTick(() => {
  176. this.$refs.timer.startTimer()
  177. })
  178. })
  179. .catch(() => {
  180. this.sendOtpLoading = false
  181. })
  182. },
  183. restartOtpInterval () {
  184. this.clearOtpInterval()
  185. this.otpInterval = setInterval(() => {
  186. if (this.otpTimer === 0) {
  187. clearInterval(this.otpInterval)
  188. } else {
  189. this.otpTimer--
  190. }
  191. }, 1000)
  192. },
  193. clearOtpInterval () {
  194. this.otpTimer = 120
  195. if (this.otpInterval) {
  196. clearInterval(this.otpInterval)
  197. }
  198. },
  199. setRegisterStep (step) {
  200. this.registerStep = step
  201. this.setBannerMessageFromStep(step)
  202. },
  203. setBannerMessageFromStep (step) {
  204. if (step === 'getUsername') {
  205. this.bannerMessage = 'بازیابی گذرواژه'
  206. } else if (step === 'verify') {
  207. this.bannerMessage = 'کد بازیابی گذرواژه'
  208. } else if (step === 'newPassword') {
  209. this.bannerMessage = 'ایجاد گذرواژه جدید'
  210. }
  211. },
  212. getToken () {
  213. return this.$store.getters['Auth/accessToken']
  214. },
  215. getEnter (targetRefKey) {
  216. this.$refs[targetRefKey].focus()
  217. },
  218. setNewPassword () {
  219. this.$axios.post(API_ADDRESS.auth.setPass, {
  220. new_password: this.password,
  221. firstname: this.firstname,
  222. lastname: this.lastname
  223. })
  224. .then(() => {
  225. this.loading = false
  226. this.redirectTo()
  227. // this.$store.commit('Auth/updateAccessToken', response.data.token.access_token)
  228. // this.$store.commit('Auth/setAccessToken', response.data.token.access_token)
  229. // this.$emit('register')
  230. })
  231. .catch(() => {
  232. this.loading = false
  233. })
  234. },
  235. goToLoginStep () {
  236. this.$emit('goToLoginStep')
  237. },
  238. showRulesAndConditions () {
  239. },
  240. redirectTo () {
  241. let redirectTo = 'Public.Home'
  242. if (this.user.canSeeAdminPanel()) {
  243. redirectTo = 'Admin.User.Index'
  244. }
  245. this.$router.push({ name: redirectTo })
  246. },
  247. goToVerifyStep () {
  248. if (!this.username) {
  249. return
  250. }
  251. this.loading = true
  252. APIGateway.auth.sendOtpForgotPassword({
  253. input: this.username
  254. })
  255. .then(() => {
  256. this.restartOtpInterval()
  257. this.loading = false
  258. this.setRegisterStep('verify')
  259. })
  260. .catch(() => {
  261. this.loading = false
  262. })
  263. },
  264. verify () {
  265. if (!this.verifyNumber) {
  266. return
  267. }
  268. this.loading = true
  269. this.$store.dispatch('Auth/setPassword', {
  270. input: this.username,
  271. password: this.password,
  272. otp: this.verifyNumber
  273. })
  274. .then(() => {
  275. this.loading = false
  276. this.redirectTo()
  277. // this.setRegisterStep('newPassword')
  278. })
  279. .catch(() => {
  280. this.loading = false
  281. })
  282. },
  283. goToGetUsernameStep () {
  284. this.setRegisterStep('getUsername')
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="scss" scopedresend-timer-message>
  290. .banner {
  291. margin-bottom: 13px;
  292. }
  293. .hello {
  294. margin-bottom: 8px;
  295. }
  296. .username-input {
  297. margin-top: 18px;
  298. }
  299. .username-input {
  300. margin-bottom: 20px;
  301. }
  302. .accept-rules-and-conditions-message {
  303. color: #212121;
  304. margin-bottom: 30px;
  305. .accept-rules-and-conditions-message-btn {
  306. color: #5B7A5F;
  307. cursor: pointer;
  308. }
  309. }
  310. .btn-GoToVerify {
  311. margin-bottom: 40px;
  312. font-size: 18px;
  313. }
  314. .go-to-login-message {
  315. font-size: 16px;
  316. .btn-go-to-login-span {
  317. color: #5B7A5F;
  318. cursor: pointer;
  319. }
  320. }
  321. .resend-timer-message {
  322. margin-bottom: 20px;
  323. text-align: center;
  324. .resend-timer-message-value {
  325. }
  326. }
  327. .btn-verifyUsername {
  328. margin-bottom: 40px;
  329. }
  330. .go-to-set-username-message {
  331. color: #5B7A5F;
  332. font-size: 16px;
  333. text-align: center;
  334. cursor: pointer;
  335. }
  336. .newPassword-top-message {
  337. margin-bottom: 3px;
  338. }
  339. .name-input, .lastname-input {
  340. margin-bottom: 25px;
  341. }
  342. .name-input, .lastname-input, .password-input {
  343. margin-top: 8px;
  344. }
  345. .password-input {
  346. margin-bottom: 54px;
  347. }
  348. </style>