RegisterStep.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. return {
  183. sendOtpLoading: false,
  184. timerEnded: false,
  185. loading: false,
  186. visibilityIcon: 'visibility',
  187. bannerMessage: 'ثبت نام در سامانه',
  188. registerStep: 'getUsername',
  189. username: null,
  190. verifyNumber: null,
  191. firstname: null,
  192. lastname: null,
  193. password: null,
  194. rePassword: null,
  195. otpInterval: null,
  196. otpTimer: 120,
  197. userLogin: false,
  198. loadingList: false,
  199. otpStep: 'sendOtp',
  200. otp: null
  201. }
  202. },
  203. computed: {
  204. user () {
  205. return this.$store.getters['Auth/user']
  206. },
  207. formatedTimer () {
  208. const second = this.otpTimer % 60
  209. const minute = Math.floor(this.otpTimer / 60)
  210. return minute + ':' + second
  211. }
  212. },
  213. created () {
  214. // if (this.getToken()) {
  215. // this.getUserData(() => { this.redirectTo() })
  216. // }
  217. this.setRegisterStep('getUsername')
  218. },
  219. methods: {
  220. toggleVisibilityIcon () {
  221. this.visibilityIcon = this.visibilityIcon === 'visibility' ? 'visibility_off' : 'visibility'
  222. },
  223. onStopTimer () {
  224. this.timerEnded = true
  225. },
  226. restartTimer () {
  227. this.sendOtpSignUp()
  228. },
  229. sendOtpSignUp () {
  230. if (!this.username) {
  231. this.$q.notify({
  232. type: 'negative',
  233. message: 'ایمیل یا شماره تلفن همراه را وارد کنید.'
  234. })
  235. return
  236. }
  237. this.sendOtpLoading = true
  238. APIGateway.auth.sendOtpSignUp({ input: this.username })
  239. .then(() => {
  240. this.sendOtpLoading = false
  241. this.timerEnded = false
  242. this.$nextTick(() => {
  243. this.$refs.timer.startTimer()
  244. })
  245. })
  246. .catch(() => {
  247. this.sendOtpLoading = false
  248. })
  249. },
  250. restartOtpInterval () {
  251. this.clearOtpInterval()
  252. this.otpInterval = setInterval(() => {
  253. if (this.otpTimer === 0) {
  254. clearInterval(this.otpInterval)
  255. } else {
  256. this.otpTimer--
  257. }
  258. }, 1000)
  259. },
  260. clearOtpInterval () {
  261. this.otpTimer = 120
  262. if (this.otpInterval) {
  263. clearInterval(this.otpInterval)
  264. }
  265. },
  266. setRegisterStep (step) {
  267. this.registerStep = step
  268. this.setBannerMessageFromStep(step)
  269. },
  270. setBannerMessageFromStep (step) {
  271. if (step === 'getUsername') {
  272. this.bannerMessage = 'ثبت نام در سامانه'
  273. } else if (step === 'verify') {
  274. this.bannerMessage = 'کد تایید'
  275. } else if (step === 'information') {
  276. this.bannerMessage = 'اطلاعات کاربری'
  277. }
  278. },
  279. getToken () {
  280. return this.$store.getters['Auth/accessToken']
  281. },
  282. getEnter (targetRefKey) {
  283. this.$refs[targetRefKey].focus()
  284. },
  285. redirectTo () {
  286. let redirectTo = window.localStorage.getItem('redirectTo')
  287. if (!redirectTo) {
  288. redirectTo = 'Admin.Content.Index'
  289. }
  290. if (!this.user.isSuperUser()) {
  291. redirectTo = 'Admin.Installment.Index'
  292. }
  293. this.$router.push({ name: redirectTo })
  294. },
  295. register () {
  296. if (!this.firstname || !this.lastname || !this.password) {
  297. this.$q.notify({
  298. type: 'negative',
  299. message: 'نام و نام خانوادگی و کلمه عبور را وارد کنید.'
  300. })
  301. return
  302. }
  303. this.$axios.post(API_ADDRESS.auth.setPass, {
  304. new_password: this.password,
  305. firstname: this.firstname,
  306. lastname: this.lastname
  307. })
  308. .then(() => {
  309. this.loading = false
  310. this.$router.push({ name: 'Public.Home' })
  311. // this.$store.commit('Auth/updateAccessToken', response.data.token.access_token)
  312. // this.$store.commit('Auth/setAccessToken', response.data.token.access_token)
  313. // this.$emit('register')
  314. })
  315. .catch(() => {
  316. this.loading = false
  317. })
  318. },
  319. goToLoginStep () {
  320. this.$emit('goToLoginStep')
  321. },
  322. showRulesAndConditions () {
  323. },
  324. goToVerifyStep () {
  325. if (!this.username) {
  326. this.$q.notify({
  327. type: 'negative',
  328. message: 'ایمیل یا شماره تلفن همراه را وارد کنید.'
  329. })
  330. return
  331. }
  332. this.loading = true
  333. APIGateway.auth.sendOtpSignUp({ input: this.username })
  334. .then(() => {
  335. this.loading = false
  336. this.restartOtpInterval()
  337. // this.$axios.defaults.headers.common.Authorization = 'Bearer ' + this.$store.getters['Auth/accessToken']
  338. // this.redirectTo()
  339. this.setRegisterStep('verify')
  340. })
  341. .catch(() => {
  342. this.loading = false
  343. })
  344. },
  345. verify () {
  346. if (!this.verifyNumber) {
  347. this.$q.notify({
  348. type: 'negative',
  349. message: 'کد تایید شماره همراه را وارد نکرده اید'
  350. })
  351. return
  352. }
  353. if (!this.firstname) {
  354. this.$q.notify({
  355. type: 'negative',
  356. message: 'نام را وارد نکرده اید'
  357. })
  358. return
  359. }
  360. if (!this.lastname) {
  361. this.$q.notify({
  362. type: 'negative',
  363. message: ' نام خانوادگی را وارد نکرده اید'
  364. })
  365. return
  366. }
  367. if (this.rePassword !== this.password) {
  368. this.$q.notify({
  369. type: 'negative',
  370. message: 'نام کلمه عبور و تکرار کلمه عبور یکسان نیستند'
  371. })
  372. return
  373. }
  374. this.loading = true
  375. this.$store.dispatch('Auth/signUp', {
  376. input: this.username,
  377. otp: this.verifyNumber,
  378. password: this.password,
  379. firstname: this.firstname,
  380. lastname: this.lastname
  381. })
  382. .then(() => {
  383. this.loading = false
  384. this.$router.push({ name: 'Public.Home' })
  385. // this.setRegisterStep('information')
  386. })
  387. .catch(() => {
  388. this.loading = false
  389. })
  390. },
  391. goToGetUsernameStep () {
  392. this.setRegisterStep('getUsername')
  393. }
  394. }
  395. }
  396. </script>
  397. <style lang="scss" scopedresend-timer-message>
  398. .banner {
  399. margin-bottom: 13px;
  400. }
  401. .hello {
  402. margin-bottom: 8px;
  403. }
  404. .username-input {
  405. margin-top: 18px;
  406. }
  407. .username-input {
  408. margin-bottom: 20px;
  409. }
  410. .accept-rules-and-conditions-message {
  411. color: #212121;
  412. margin-bottom: 30px;
  413. .accept-rules-and-conditions-message-btn {
  414. color: #5B7A5F;
  415. cursor: pointer;
  416. }
  417. }
  418. .btn-GoToVerify {
  419. margin-bottom: 40px;
  420. font-size: 18px;
  421. }
  422. .go-to-login-message {
  423. font-size: 16px;
  424. .btn-go-to-login-span {
  425. color: #5B7A5F;
  426. cursor: pointer;
  427. }
  428. }
  429. .resend-timer-message {
  430. margin-bottom: 20px;
  431. text-align: center;
  432. .resend-timer-message-value {
  433. }
  434. }
  435. .btn-verifyUsername {
  436. margin-bottom: 40px;
  437. }
  438. .go-to-set-username-message {
  439. color: #5B7A5F;
  440. font-size: 16px;
  441. text-align: center;
  442. cursor: pointer;
  443. }
  444. .information-top-message {
  445. margin-bottom: 3px;
  446. }
  447. .name-input, .lastname-input {
  448. margin-bottom: 25px;
  449. }
  450. .name-input, .lastname-input, .password-input {
  451. margin-top: 8px;
  452. }
  453. .password-input {
  454. margin-bottom: 54px;
  455. }
  456. </style>