| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- <template>
- <div>
- <q-banner class="banner">
- {{ bannerMessage }}
- </q-banner>
- <template v-if="registerStep === 'getUsername'">
- <label for="username">
- ایمیل یا شماره تلفن همراه
- </label>
- <q-input id="username"
- v-model="username"
- outlined
- class="username-input"
- placeholder="ایمیل یا شماره تلفن همراه"
- :disable="loading"
- :loading="loading"
- @keydown.enter="goToVerifyStep">
- <template v-slot:prepend>
- <q-icon name="person" />
- </template>
- </q-input>
- <q-btn class="full-width btn-GoToVerify"
- color="primary"
- label="ارسال کد بازیابی"
- :disable="loading"
- :loading="loading"
- @click="goToVerifyStep" />
- <div class="go-to-login-message">
- گذرواژه را به خاطر دارید؟
- <span class="btn-go-to-login-span"
- @click="goToLoginStep">
- وارد شوید
- </span>
- </div>
- </template>
- <template v-else-if="registerStep === 'verify'">
- <label for="verifyNumber">
- .لطفا کد تایید ارسال شده به شماره
- {{ username }}
- را وارد کنید
- </label>
- <q-input id="verifyNumber"
- v-model="verifyNumber"
- outlined
- class="username-input"
- label=""
- :disable="loading"
- :loading="loading" />
- <div class="resend-timer-message">
- <template v-if="!timerEnded">
- <span class="resend-timer-message-value">
- <timer ref="timer"
- :time="120"
- @stop="onStopTimer" />
- </span>
- تا درخواست مجدد
- </template>
- <template v-else>
- <q-btn color="primary"
- class="full-width"
- :loading="sendOtpLoading"
- @click="restartTimer">
- ارسال مجدد کد تایید
- </q-btn>
- </template>
- </div>
- <label class="password-label"
- for="password">
- گذرواژه
- </label>
- <q-input id="password"
- v-model="password"
- outlined
- class="password-input"
- type="password"
- placeholder="گذرواژه جدید خود را وارد کنید"
- @keydown.enter="verify">
- <template v-slot:prepend>
- <q-icon name="person" />
- </template>
- <template v-slot:append>
- <q-icon name="person" />
- </template>
- </q-input>
- <q-btn class="full-width btn-verifyUsername"
- color="primary"
- label="تایید و ورود"
- :disable="loading"
- :loading="loading"
- @click="verify" />
- <div class="go-to-set-username-message"
- @click="goToGetUsernameStep">
- تغییر شماره تلفن همراه یا استفاده از آدرس ایمیل
- </div>
- </template>
- <template v-else-if="registerStep === 'newPassword'">
- <q-btn class="full-width btn-login"
- color="primary"
- label="تایید و ورود"
- @click="setNewPassword" />
- </template>
- </div>
- </template>
- <script>
- import API_ADDRESS from 'src/api/Addresses.js'
- import { mixinAuth } from 'src/mixin/Mixins.js'
- import Timer from 'src/components/Auth/Timer.vue'
- import { APIGateway } from 'src/api/APIGateway.js'
- export default {
- name: 'ForgetStep',
- components: { Timer },
- mixins: [mixinAuth],
- props: {
- redirect: {
- type: Boolean,
- default: false
- }
- },
- data: () => ({
- sendOtpLoading: false,
- timerEnded: false,
- loading: false,
- bannerMessage: 'بازیابی گذرواژه',
- registerStep: 'getUsername',
- username: null,
- verifyNumber: null,
- firstname: null,
- lastname: null,
- password: null,
- otpInterval: null,
- otpTimer: 120,
- userLogin: false,
- loadingList: false,
- otpStep: 'sendOtp',
- otp: null
- }),
- computed: {
- user () {
- return this.$store.getters['Auth/user']
- },
- formatedTimer () {
- const second = this.otpTimer % 60
- const minute = Math.floor(this.otpTimer / 60)
- return minute + ':' + second
- }
- },
- created () {
- // if (this.getToken()) {
- // this.getUserData(() => { this.redirectTo() })
- // }
- this.setRegisterStep('getUsername')
- this.$store.dispatch('Auth/logOut')
- },
- methods: {
- onStopTimer () {
- this.timerEnded = true
- },
- restartTimer () {
- this.sendOtpForgotPassword()
- },
- sendOtpForgotPassword () {
- this.sendOtpLoading = true
- APIGateway.auth.sendOtpForgotPassword({
- input: this.username
- })
- .then(() => {
- this.sendOtpLoading = false
- this.timerEnded = false
- this.$nextTick(() => {
- this.$refs.timer.startTimer()
- })
- })
- .catch(() => {
- this.sendOtpLoading = false
- })
- },
- restartOtpInterval () {
- this.clearOtpInterval()
- this.otpInterval = setInterval(() => {
- if (this.otpTimer === 0) {
- clearInterval(this.otpInterval)
- } else {
- this.otpTimer--
- }
- }, 1000)
- },
- clearOtpInterval () {
- this.otpTimer = 120
- if (this.otpInterval) {
- clearInterval(this.otpInterval)
- }
- },
- setRegisterStep (step) {
- this.registerStep = step
- this.setBannerMessageFromStep(step)
- },
- setBannerMessageFromStep (step) {
- if (step === 'getUsername') {
- this.bannerMessage = 'بازیابی گذرواژه'
- } else if (step === 'verify') {
- this.bannerMessage = 'کد بازیابی گذرواژه'
- } else if (step === 'newPassword') {
- this.bannerMessage = 'ایجاد گذرواژه جدید'
- }
- },
- getToken () {
- return this.$store.getters['Auth/accessToken']
- },
- getEnter (targetRefKey) {
- this.$refs[targetRefKey].focus()
- },
- setNewPassword () {
- this.$axios.post(API_ADDRESS.auth.setPass, {
- new_password: this.password,
- firstname: this.firstname,
- lastname: this.lastname
- })
- .then(() => {
- this.loading = false
- this.redirectTo()
- // this.$store.commit('Auth/updateAccessToken', response.data.token.access_token)
- // this.$store.commit('Auth/setAccessToken', response.data.token.access_token)
- // this.$emit('register')
- })
- .catch(() => {
- this.loading = false
- })
- },
- goToLoginStep () {
- this.$emit('goToLoginStep')
- },
- showRulesAndConditions () {
- },
- redirectTo () {
- let redirectTo = 'Public.Home'
- if (this.user.canSeeAdminPanel()) {
- redirectTo = 'Admin.User.Index'
- }
- this.$router.push({ name: redirectTo })
- },
- goToVerifyStep () {
- if (!this.username) {
- return
- }
- this.loading = true
- APIGateway.auth.sendOtpForgotPassword({
- input: this.username
- })
- .then(() => {
- this.restartOtpInterval()
- this.loading = false
- this.setRegisterStep('verify')
- })
- .catch(() => {
- this.loading = false
- })
- },
- verify () {
- if (!this.verifyNumber) {
- return
- }
- this.loading = true
- this.$store.dispatch('Auth/setPassword', {
- input: this.username,
- password: this.password,
- otp: this.verifyNumber
- })
- .then(() => {
- this.loading = false
- this.redirectTo()
- // this.setRegisterStep('newPassword')
- })
- .catch(() => {
- this.loading = false
- })
- },
- goToGetUsernameStep () {
- this.setRegisterStep('getUsername')
- }
- }
- }
- </script>
- <style lang="scss" scopedresend-timer-message>
- .banner {
- margin-bottom: 13px;
- }
- .hello {
- margin-bottom: 8px;
- }
- .username-input {
- margin-top: 18px;
- }
- .username-input {
- margin-bottom: 20px;
- }
- .accept-rules-and-conditions-message {
- color: #212121;
- margin-bottom: 30px;
- .accept-rules-and-conditions-message-btn {
- color: #5B7A5F;
- cursor: pointer;
- }
- }
- .btn-GoToVerify {
- margin-bottom: 40px;
- font-size: 18px;
- }
- .go-to-login-message {
- font-size: 16px;
- .btn-go-to-login-span {
- color: #5B7A5F;
- cursor: pointer;
- }
- }
- .resend-timer-message {
- margin-bottom: 20px;
- text-align: center;
- .resend-timer-message-value {
- }
- }
- .btn-verifyUsername {
- margin-bottom: 40px;
- }
- .go-to-set-username-message {
- color: #5B7A5F;
- font-size: 16px;
- text-align: center;
- cursor: pointer;
- }
- .newPassword-top-message {
- margin-bottom: 3px;
- }
- .name-input, .lastname-input {
- margin-bottom: 25px;
- }
- .name-input, .lastname-input, .password-input {
- margin-top: 8px;
- }
- .password-input {
- margin-bottom: 54px;
- }
- </style>
|