mirror of
https://github.com/Dadechin/XRoomDashboardFront.git
synced 2025-07-04 17:24:35 +00:00
added sms verification
This commit is contained in:
parent
3866b1bb44
commit
01ebe2c0b8
|
@ -81,7 +81,7 @@ export default {
|
||||||
logout() {
|
logout() {
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
window.location.href = '/login';
|
window.location.href = '/';
|
||||||
},
|
},
|
||||||
closeDropdown(event) {
|
closeDropdown(event) {
|
||||||
if (!this.$el.contains(event.target)) {
|
if (!this.$el.contains(event.target)) {
|
||||||
|
|
|
@ -102,7 +102,7 @@ export default {
|
||||||
});
|
});
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
alert('رمز عبور با موفقیت بازنشانی شد.');
|
alert('رمز عبور با موفقیت بازنشانی شد.');
|
||||||
this.$router.push('/login');
|
this.$router.push('/');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error resetting password:', error);
|
console.error('Error resetting password:', error);
|
||||||
|
|
|
@ -79,6 +79,11 @@ export default {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('http://194.62.43.230:8000/signup', signupData);
|
const response = await axios.post('http://194.62.43.230:8000/signup', signupData);
|
||||||
console.log('Signup success:', response.data);
|
console.log('Signup success:', response.data);
|
||||||
|
const token = response.data.token;
|
||||||
|
|
||||||
|
|
||||||
|
localStorage.setItem('token', token);
|
||||||
|
|
||||||
// Redirect to login page upon successful signup
|
// Redirect to login page upon successful signup
|
||||||
this.$router.push('/');
|
this.$router.push('/');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -10,9 +10,21 @@
|
||||||
پیامکی شامل کد تایید به موبایل شما ارسال شده است.
|
پیامکی شامل کد تایید به موبایل شما ارسال شده است.
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
<button type="submit" style="margin-bottom: 35px;" class="submit-btn" @click="sendSms">
|
<button
|
||||||
ارسال مجدد کد
|
type="button"
|
||||||
</button>
|
class="submit-btn"
|
||||||
|
style="margin-bottom: 35px;"
|
||||||
|
:disabled="isButtonDisabled"
|
||||||
|
@click="sendSms"
|
||||||
|
>
|
||||||
|
<span v-if="isButtonDisabled">
|
||||||
|
ارسال مجدد کد ({{ Math.floor(countdown / 60) }}:{{ String(countdown % 60).padStart(2, '0') }})
|
||||||
|
</span>
|
||||||
|
<span v-else>
|
||||||
|
ارسال مجدد کد
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
<!-- Step 1: Mobile Number Input -->
|
<!-- Step 1: Mobile Number Input -->
|
||||||
<!-- <form v-if="!codeSent" @submit.prevent="requestResetCode">
|
<!-- <form v-if="!codeSent" @submit.prevent="requestResetCode">
|
||||||
|
@ -59,7 +71,8 @@
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import apiClient from '@/api/axios'; // Adjust the path based on your project structure
|
// import apiClient from '@/api/axios'; // Adjust the path based on your project structure
|
||||||
|
import axios from '@/axios';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
@ -70,42 +83,93 @@ export default {
|
||||||
password: '',
|
password: '',
|
||||||
},
|
},
|
||||||
codeSent: false, // Tracks if the code has been sent
|
codeSent: false, // Tracks if the code has been sent
|
||||||
|
|
||||||
|
|
||||||
|
isButtonDisabled: false,
|
||||||
|
countdown: 120, // in seconds (2 minutes)
|
||||||
|
countdownInterval: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
const token = localStorage.getItem('token');
|
||||||
|
if (!token) {
|
||||||
|
window.location.reload();
|
||||||
|
} else {
|
||||||
|
this.sendSms(); // Automatically call sendSms on mount
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async sendSms() {
|
async sendSms() {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
|
|
||||||
const response = await apiClient.get('/sendSmsVerification', {
|
|
||||||
// mobile_number: this.form.mobileNumber,
|
|
||||||
}, {
|
|
||||||
'Authorization': `Token ${token}`,
|
|
||||||
'Content-Type': 'multipart/form-data'
|
|
||||||
});
|
|
||||||
// const response = await axios.post(uploadUrl, formData, {
|
|
||||||
// headers: {
|
|
||||||
// 'Authorization': `Token ${token}`,
|
|
||||||
// 'Content-Type': 'multipart/form-data'
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (response.data.success) {
|
const response = await axios.get('/sendSmsVerification', {
|
||||||
this.codeSent = true;
|
headers: {
|
||||||
alert('کد تأیید به شماره موبایل شما ارسال شد.');
|
'Authorization': `Token ${token}`,
|
||||||
}
|
'Content-Type': 'multipart/form-data',
|
||||||
} catch (error) {
|
},
|
||||||
console.error('Error requesting reset code:', error);
|
});
|
||||||
alert('خطا در ارسال کد تأیید. لطفاً دوباره تلاش کنید.');
|
|
||||||
|
if (response.status == 200) {
|
||||||
|
this.codeSent = true;
|
||||||
|
alert('کد تأیید به شماره موبایل شما ارسال شد.');
|
||||||
|
this.startCountdown(); // Start countdown when code is sent
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error requesting reset code:', error);
|
||||||
|
alert('خطا در ارسال کد تأیید. لطفاً دوباره تلاش کنید.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
startCountdown() {
|
||||||
|
this.isButtonDisabled = true;
|
||||||
|
this.countdown = 120; // Reset to 2 minutes
|
||||||
|
|
||||||
|
if (this.countdownInterval) {
|
||||||
|
clearInterval(this.countdownInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.countdownInterval = setInterval(() => {
|
||||||
|
if (this.countdown > 0) {
|
||||||
|
this.countdown--;
|
||||||
|
} else {
|
||||||
|
this.isButtonDisabled = false;
|
||||||
|
clearInterval(this.countdownInterval);
|
||||||
}
|
}
|
||||||
},
|
}, 1000);
|
||||||
|
},
|
||||||
|
|
||||||
async submitSmsVerification() {
|
async submitSmsVerification() {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.post('/submitSmsVerification', {
|
const token = localStorage.getItem('token');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const response = await axios.post('/submitSmsVerification',
|
||||||
|
{
|
||||||
|
verification_sms_code: this.form.code,
|
||||||
|
|
||||||
|
}, {headers: {
|
||||||
|
|
||||||
verification_sms_code: this.form.code,
|
'Authorization': `Token ${token}`,
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
|
||||||
|
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// const response = await apiClient.post('/submitSmsVerification', {
|
||||||
|
|
||||||
|
|
||||||
|
// verification_sms_code: this.form.code,
|
||||||
|
|
||||||
|
// });
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
alert('رمز عبور با موفقیت بازنشانی شد.');
|
alert('رمز عبور با موفقیت بازنشانی شد.');
|
||||||
this.$router.push('/dashboard');
|
this.$router.push('/dashboard');
|
||||||
|
|
|
@ -13,12 +13,7 @@ const routes = [
|
||||||
path: '/signup',
|
path: '/signup',
|
||||||
name: 'SignupPage',
|
name: 'SignupPage',
|
||||||
component: SignupPage
|
component: SignupPage
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/login',
|
|
||||||
name: 'LoginPage',
|
|
||||||
component: LoginPage
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'LoginPage',
|
name: 'LoginPage',
|
||||||
|
@ -90,7 +85,7 @@ router.beforeEach(async (to, from, next) => {
|
||||||
|
|
||||||
// If route requires auth but no token, redirect to login
|
// If route requires auth but no token, redirect to login
|
||||||
if (requiresAuth && !token) {
|
if (requiresAuth && !token) {
|
||||||
return next('/login');
|
return next('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a token and it's an auth route, verify it
|
// If we have a token and it's an auth route, verify it
|
||||||
|
@ -109,7 +104,7 @@ router.beforeEach(async (to, from, next) => {
|
||||||
localStorage.setItem('baseUrl','http://194.62.43.230:8000');
|
localStorage.setItem('baseUrl','http://194.62.43.230:8000');
|
||||||
|
|
||||||
// If trying to access login page while authenticated, redirect to dashboard
|
// If trying to access login page while authenticated, redirect to dashboard
|
||||||
if (to.path === '/login') {
|
if (to.path === '/') {
|
||||||
return next('/dashboard');
|
return next('/dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +125,7 @@ router.beforeEach(async (to, from, next) => {
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
localStorage.removeItem('customer');
|
localStorage.removeItem('customer');
|
||||||
return next('/login');
|
return next('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user