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() {
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('token');
|
||||
window.location.href = '/login';
|
||||
window.location.href = '/';
|
||||
},
|
||||
closeDropdown(event) {
|
||||
if (!this.$el.contains(event.target)) {
|
||||
|
|
|
@ -102,7 +102,7 @@ export default {
|
|||
});
|
||||
if (response.data.success) {
|
||||
alert('رمز عبور با موفقیت بازنشانی شد.');
|
||||
this.$router.push('/login');
|
||||
this.$router.push('/');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error resetting password:', error);
|
||||
|
|
|
@ -79,6 +79,11 @@ export default {
|
|||
try {
|
||||
const response = await axios.post('http://194.62.43.230:8000/signup', signupData);
|
||||
console.log('Signup success:', response.data);
|
||||
const token = response.data.token;
|
||||
|
||||
|
||||
localStorage.setItem('token', token);
|
||||
|
||||
// Redirect to login page upon successful signup
|
||||
this.$router.push('/');
|
||||
} catch (error) {
|
||||
|
|
|
@ -10,9 +10,21 @@
|
|||
پیامکی شامل کد تایید به موبایل شما ارسال شده است.
|
||||
</h5>
|
||||
|
||||
<button type="submit" style="margin-bottom: 35px;" class="submit-btn" @click="sendSms">
|
||||
ارسال مجدد کد
|
||||
</button>
|
||||
<button
|
||||
type="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 -->
|
||||
<!-- <form v-if="!codeSent" @submit.prevent="requestResetCode">
|
||||
|
@ -59,7 +71,8 @@
|
|||
|
||||
|
||||
<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 {
|
||||
data() {
|
||||
|
@ -70,42 +83,93 @@ export default {
|
|||
password: '',
|
||||
},
|
||||
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: {
|
||||
async sendSms() {
|
||||
try {
|
||||
const token = localStorage.getItem('token');
|
||||
try {
|
||||
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'
|
||||
// }
|
||||
// });
|
||||
const response = await axios.get('/sendSmsVerification', {
|
||||
headers: {
|
||||
'Authorization': `Token ${token}`,
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
|
||||
if (response.data.success) {
|
||||
this.codeSent = true;
|
||||
alert('کد تأیید به شماره موبایل شما ارسال شد.');
|
||||
}
|
||||
} 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() {
|
||||
try {
|
||||
const response = await apiClient.post('/submitSmsVerification', {
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
verification_sms_code: this.form.code,
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const response = await axios.post('/submitSmsVerification',
|
||||
{
|
||||
verification_sms_code: this.form.code,
|
||||
|
||||
}, {headers: {
|
||||
|
||||
'Authorization': `Token ${token}`,
|
||||
'Content-Type': 'multipart/form-data'
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// const response = await apiClient.post('/submitSmsVerification', {
|
||||
|
||||
|
||||
// verification_sms_code: this.form.code,
|
||||
|
||||
// });
|
||||
if (response.status == 200) {
|
||||
alert('رمز عبور با موفقیت بازنشانی شد.');
|
||||
this.$router.push('/dashboard');
|
||||
|
|
|
@ -14,11 +14,6 @@ const routes = [
|
|||
name: 'SignupPage',
|
||||
component: SignupPage
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'LoginPage',
|
||||
component: LoginPage
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
name: 'LoginPage',
|
||||
|
@ -90,7 +85,7 @@ router.beforeEach(async (to, from, next) => {
|
|||
|
||||
// If route requires auth but no token, redirect to login
|
||||
if (requiresAuth && !token) {
|
||||
return next('/login');
|
||||
return next('/');
|
||||
}
|
||||
|
||||
// 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');
|
||||
|
||||
// If trying to access login page while authenticated, redirect to dashboard
|
||||
if (to.path === '/login') {
|
||||
if (to.path === '/') {
|
||||
return next('/dashboard');
|
||||
}
|
||||
|
||||
|
@ -130,7 +125,7 @@ router.beforeEach(async (to, from, next) => {
|
|||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('customer');
|
||||
return next('/login');
|
||||
return next('/');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user