ForgetStep.vue 8.9 KB

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