RegisterStep.vue 12 KB

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