Skip to content

Commit

Permalink
fix front
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariiiii committed Nov 11, 2024
1 parent 72989e5 commit 8df18db
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 35 deletions.
10 changes: 6 additions & 4 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
function isAuthenticated() {
return localStorage.getItem('authToken');
}

function redirectToPage() {
const currentPath = window.location.pathname;
if (isAuthenticated() && currentPath === '/login') {
window.location.href = '/client/main';
} else if (!isAuthenticated() && currentPath !== '/login') {
if (currentPath === '/') {
window.location.href = '/login';
} else if (isAuthenticated() && currentPath === '/login') {
window.location.href = '/client/main';
} else if (!isAuthenticated() && currentPath !== '/login') {
window.location.href = '/login';
}
}

window.onload = redirectToPage;
</script>
</head>
Expand Down
25 changes: 19 additions & 6 deletions frontend/src/components/NavBar.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
<template>
<nav>
<ul>
<li><router-link to="/">SCAM-BANK</router-link></li>
<li><router-link to="/credit">Кредиты</router-link></li>
<li><router-link to="/request">Заявки</router-link></li>
<li><router-link to="/profile">Профиль</router-link></li>
<li v-if="isClient"><router-link to="/client/main">SCAM-BANK</router-link></li>
<li v-if="isAdmin"><router-link to="/admin/main">SCAM-BANK</router-link></li>
<li v-if="isClient"><router-link to="/client/credit">Кредиты</router-link></li>
<!-- <li v-if="isAdmin"><router-link to="/admin/">Cтатистика</router-link></li> -->
<li v-if="isClient"><router-link to="/client/request">Заявки</router-link></li>
<li v-if="isAdmin"><router-link to="/admin/request">Заявки</router-link></li>
<!-- <li v-if="isAdmin"><router-link to="/admin/">История</router-link></li> -->
<li v-if="isClient"><router-link to="/client/profile">Профиль</router-link></li>
<li v-if="isAdmin"><router-link to="/admin/profile">Профиль</router-link></li>
</ul>
</nav>
</template>

<script>
export default {
name: 'NavBar'
name: 'NavBar',
computed: {
isClient() {
return localStorage.getItem('userType') === 'client';
},
isAdmin() {
return localStorage.getItem('userType') === 'admin';
},
},
};
</script>

Expand Down Expand Up @@ -42,4 +55,4 @@ a {
a:hover {
text-decoration: underline;
}
</style>
</style>
22 changes: 9 additions & 13 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import Vue from 'vue';
import VueRouter from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import Login from '../views/Login.vue';
import ClientMain from '../views/client/Main.vue';
import AdminMain from '../views/admin/Main.vue';
import ClientCredit from '../views/client/Credit.vue';
// import AdminCredit from '../views/admin/Credit.vue';
import ClientRequest from '../views/client/Request.vue';
// import AdminRequest from '../views/admin/Request.vue';
import AdminRequest from '../views/admin/Request.vue';
import ClientProfile from '../views/client/Profile.vue';
// import AdminProfile from '../views/admin/Profile.vue';
import AdminProfile from '../views/admin/Profile.vue';
import ClientLoanApplication from '../views/client/LoanApplication.vue';

Vue.use(VueRouter);

const routes = [
{ path: '/login', component: Login },
// { path: '/', redirect: '/login' },
{ path: '/login', component: Login, meta: { hideNavBar: true } },
{ path: '/client/main', component: ClientMain },
{ path: '/admin/main', component: AdminMain },
{ path: '/client/credit', component: ClientCredit },
// { path: '/admin/credit', component: AdminCredit },
{ path: '/client/request', component: ClientRequest },
// { path: '/admin/request', component: AdminRequest },
{ path: '/admin/request', component: AdminRequest },
{ path: '/client/profile', component: ClientProfile },
// { path: '/admin/profile', component: AdminProfile },
{ path: '/admin/profile', component: AdminProfile },
{ path: '/client/loan-application', component: ClientLoanApplication },

];

const router = new VueRouter({
const router = createRouter({
history: createWebHistory(),
routes,
});

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ export default {
const response = await axios.post('http://127.0.0.1:5000/login', {
email: this.email,
password: this.password
});
if (response.data.token) {
localStorage.setItem('authToken', response.data.token);
localStorage.setItem('authToken', true);
localStorage.setItem('userId', response.data.userId);
localStorage.setItem('userType', response.data.userType);
this.$router.push(`/${responce.data.userType}/main`);
this.$router.push(`/${response.data.userType}/main`);
}
}
catch (error) {
Expand All @@ -51,6 +50,7 @@ export default {
}
else {
alert('Произошла ошибка. Пожалуйста, попробуйте позже.');
console.log(error);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/admin/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script>
export default {
name: 'Main'
name: 'AdminMain'
};
</script>

Expand Down
27 changes: 27 additions & 0 deletions frontend/src/views/admin/Profile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div>
<h1>Профиль</h1>
<p>Здесь будет информация о вашем профиле.</p>
<Button text="Выход" @click="logout" />
</div>
</template>

<script>
import Button from '../../components/Button.vue';
export default {
name: 'AdminProfile',
components: {
Button
},
methods: {
logout() {
localStorage.setItem('authToken', false);
this.$router.push('/login');
}
}
};
</script>

<style scoped>
</style>
15 changes: 15 additions & 0 deletions frontend/src/views/admin/Request.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<div>
<h1>Заявки</h1>
<p>Здесь можно посмотреть заявки.</p>
</div>
</template>

<script>
export default {
name: 'AdminRequest'
};
</script>

<style scoped>
</style>
4 changes: 3 additions & 1 deletion frontend/src/views/client/LoanApplication.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ export default {
loanAmount: this.loanAmount,
loanTerm: this.loanTerm,
coBorrowers: this.coBorrowers,
collateral: this.collateral
collateral: this.collateral,
clientId: localStorage.getItem('clientId') || null
};
try {
const response = await axios.post('http://127.0.0.1:5000/credit_request', loanData);
console.log('Заявка на кредит отправлена:', response.data);
console.log(loanData);
alert('Заявка на кредит успешно отправлена!');
} catch (error) {
console.error('Ошибка при отправке заявки на кредит:', error);
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/views/client/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<h1>Добро пожаловать, user!</h1>
<h2>Оформление кредита</h2>
<ul>
<li><router-link to="/loan-application">Оформить кредит 1</router-link></li>
<li><router-link to="/loan-application">Оформить кредит 2</router-link></li>
<li><router-link to="/loan-application">Оформить кредит 3</router-link></li>
<li><router-link to="/loan-application">Оформить кредит 4</router-link></li>
<li><router-link to="/loan-application">Оформить кредит 5</router-link></li>
<li><router-link to="/loan-application">Оформить кредит 6</router-link></li>
<li><router-link to="/client/loan-application">Оформить кредит 1</router-link></li>
<li><router-link to="/client/loan-application">Оформить кредит 2</router-link></li>
<li><router-link to="/client/loan-application">Оформить кредит 3</router-link></li>
<li><router-link to="/client/loan-application">Оформить кредит 4</router-link></li>
<li><router-link to="/client/loan-application">Оформить кредит 5</router-link></li>
<li><router-link to="/client/loan-application">Оформить кредит 6</router-link></li>
</ul>
</div>
</template>
Expand Down

0 comments on commit 8df18db

Please sign in to comment.