[auth] Added auth guard

This commit is contained in:
Matej Glasnák committed 2023-02-22 19:09:12 +01:00
1 parent ef6369714b
commit 1e86dbbbb3
5 files changed
+44 -21

No files matched your search

+35 -12
View File
@@ -1,4 +1,5 @@
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router' import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import store from '@/store'
const routes: Array<RouteRecordRaw> = [ const routes: Array<RouteRecordRaw> = [
{ {
@@ -16,17 +17,20 @@ const routes: Array<RouteRecordRaw> = [
{ {
path: '/auth/login', path: '/auth/login',
name: 'Login', name: 'Login',
component: () => import('@/plugins/lib@auth/login/login.vue') component: () => import('@/plugins/lib@auth/login/login.vue'),
meta: {requiresAuth: false}
}, },
{ {
path: '/auth/forgot-password', path: '/auth/forgot-password',
name: 'Forgot password', name: 'Forgot password',
component: () => import('@/plugins/lib@auth/forgot-password/forgot-password.vue') component: () => import('@/plugins/lib@auth/forgot-password/forgot-password.vue'),
meta: {requiresAuth: false}
}, },
{ {
path: '/auth/reset-password', path: '/auth/reset-password',
name: 'Reset password', name: 'Reset password',
component: () => import('@/plugins/lib@auth/reset-password/reset-password.vue') component: () => import('@/plugins/lib@auth/reset-password/reset-password.vue'),
meta: {requiresAuth: false}
} }
] ]
}, },
@@ -45,50 +49,50 @@ const routes: Array<RouteRecordRaw> = [
{ {
path: '/app/dashboard/tasks', path: '/app/dashboard/tasks',
name: 'Dashboard - Tasks', name: 'Dashboard - Tasks',
meta: { title: 'Tasks' }, meta: { title: 'Tasks', requiresAuth: true },
component: () => import('@/plugins/tm@dashboard/tasks/tasks.vue') component: () => import('@/plugins/tm@dashboard/tasks/tasks.vue')
}, },
{ {
path: '/app/dashboard/teams', path: '/app/dashboard/teams',
name: 'Dashboard - Teams', name: 'Dashboard - Teams',
meta: { title: 'Teams Overview' }, meta: { title: 'Teams Overview', requiresAuth: true },
component: () => import('@/plugins/tm@dashboard/teams/teams.vue') component: () => import('@/plugins/tm@dashboard/teams/teams.vue')
}, },
{ {
path: '/app/dashboard/projects', path: '/app/dashboard/projects',
name: 'Dashboard - Projects', name: 'Dashboard - Projects',
meta: { title: 'Projects overview' }, meta: { title: 'Projects overview', requiresAuth: true },
component: () => import('@/plugins/tm@dashboard/projects/projects.vue') component: () => import('@/plugins/tm@dashboard/projects/projects.vue')
}, },
{ {
path: '/app/overview/unscheduled', path: '/app/overview/unscheduled',
name: 'Overview - Unscheduled tasks', name: 'Overview - Unscheduled tasks',
meta: { title: 'Unscheduled tasks' }, meta: { title: 'Unscheduled tasks', requiresAuth: true },
component: () => import('@/plugins/tm@overview/tasks-unscheduled/tasks-unscheduled.vue') component: () => import('@/plugins/tm@overview/tasks-unscheduled/tasks-unscheduled.vue')
}, },
{ {
path: '/app/overview/ongoing', path: '/app/overview/ongoing',
name: 'Overview - Ongoing tasks', name: 'Overview - Ongoing tasks',
meta: { title: 'Ongoing tasks' }, meta: { title: 'Ongoing tasks', requiresAuth: true },
component: () => import('@/plugins/tm@overview/tasks-ongoing/tasks-ongoing.vue') component: () => import('@/plugins/tm@overview/tasks-ongoing/tasks-ongoing.vue')
}, },
{ {
path: '/app/overview/teams', path: '/app/overview/teams',
name: 'Overview - Teams', name: 'Overview - Teams',
meta: { title: 'Teams' }, meta: { title: 'Teams', requiresAuth: true },
component: () => import('@/plugins/tm@overview/teams/teams.vue') component: () => import('@/plugins/tm@overview/teams/teams.vue')
}, },
{ {
path: '/app/dashboard/user', path: '/app/dashboard/user',
name: 'Dashboard - User', name: 'Dashboard - User',
meta: { title: 'Profile' }, meta: { title: 'Profile', requiresAuth: true },
component: () => import('@/plugins/tm@profile/profile/my-profile.vue') component: () => import('@/plugins/tm@profile/profile/my-profile.vue')
}, },
{ {
path: '/app/search', path: '/app/search',
name: 'Search', name: 'Search',
meta: { title: 'Search Results' }, meta: { title: 'Search Results', requiresAuth: true },
component: () => import('@/plugins/lib@search/search/search.vue') component: () => import('@/plugins/lib@search/search/search.vue')
} }
] ]
@@ -98,7 +102,8 @@ const routes: Array<RouteRecordRaw> = [
{ {
path: '/:catchAll(.*)', path: '/:catchAll(.*)',
name: '404', name: '404',
component: () => import('@/plugins/w@screen/404/404.vue') component: () => import('@/plugins/w@screen/404/404.vue'),
meta: {requiresAuth: null}
} }
] ]
@@ -107,4 +112,22 @@ const router = createRouter({
routes routes
}) })
router.beforeEach((to, from, next) => {
const isLoggedIn = store.getters['auth/isLoggedIn']
if (to.meta.requiresAuth === true) {
if (isLoggedIn)
return next()
else
return next({name: 'Login'})
} else if (to.meta.requiresAuth === false) {
if (!isLoggedIn)
return next()
else
return next({name: 'Dashboard - Tasks'})
} else {
return next({name: 'Login'})
}
})
export default router export default router
+2 -3
View File
@@ -35,13 +35,12 @@ export default {
splitDays() { splitDays() {
const days = [] const days = []
const workingHours = {} const workingHours = {}
const capacityPerDay = this.$store.getters['auth/user'].work_end - this.$store.getters['auth/user'].work_start
this.timelineData.tasks.forEach(task => { this.timelineData.tasks.forEach(task => {
if (!workingHours[task.split]) if (!workingHours[task.split])
workingHours[task.split] = 0 workingHours[task.split] = 0
if (task.nonWorking) if (task.nonWorking || task.subtask.is_finished)
return return
workingHours[task.split] += timelineUtils._getDifferenceInHours(task.end, task.start) workingHours[task.split] += timelineUtils._getDifferenceInHours(task.end, task.start)
@@ -52,7 +51,7 @@ export default {
id: i + 1, id: i + 1,
fullname: `${this.filter.employee.name} ${this.filter.employee.surname}`, fullname: `${this.filter.employee.name} ${this.filter.employee.surname}`,
initials: this.filter.employee.name.charAt(0).toUpperCase() + this.filter.employee.surname.charAt(0).toUpperCase(), initials: this.filter.employee.name.charAt(0).toUpperCase() + this.filter.employee.surname.charAt(0).toUpperCase(),
unscheduledTime: capacityPerDay - workingHours[i + 1], unscheduledTime: workingHours[i + 1],
date: addDays(this.filter.start, i), date: addDays(this.filter.start, i),
isWeekend: timelineUtils.isWeekend(addDays(this.filter.start, i)) isWeekend: timelineUtils.isWeekend(addDays(this.filter.start, i))
}) })
@@ -25,6 +25,7 @@
label="Nenaplánované hodiny" label="Nenaplánované hodiny"
v-model="time" v-model="time"
variant="outlined" variant="outlined"
:disabled="true"
></v-text-field> ></v-text-field>
</v-row> </v-row>
</template> </template>
+1 -2
View File
@@ -37,7 +37,6 @@ export default {
this.filter.team.employees.forEach((employee, index) => { this.filter.team.employees.forEach((employee, index) => {
let workingHours = 0 let workingHours = 0
const capacityPerDay = employee.work_end - employee.work_start
this.timelineData.tasks.forEach(task => { this.timelineData.tasks.forEach(task => {
if (task?.subtask?.employee_id == employee.id) if (task?.subtask?.employee_id == employee.id)
@@ -49,7 +48,7 @@ export default {
name: employee.name, name: employee.name,
fullname: `${employee.name} ${employee.surname}`, fullname: `${employee.name} ${employee.surname}`,
initials: employee.name.charAt(0).toUpperCase() + employee.surname.charAt(0).toUpperCase(), initials: employee.name.charAt(0).toUpperCase() + employee.surname.charAt(0).toUpperCase(),
unscheduledTime: capacityPerDay - workingHours unscheduledTime: workingHours
}) })
}) })
@@ -2,7 +2,7 @@
<v-dialog v-model="visible" max-width="750"> <v-dialog v-model="visible" max-width="750">
<v-card> <v-card>
<div class="d-flex justify-space-between align-center"> <div class="d-flex justify-space-between align-center">
<h1>Ste si istý, že chcete {{ this.subtask.is_finished ? 'znovu otvoriť' : 'dokončiť' }} task, z masterTasku <b>{{ subtask?.master_task?.name || subtask.master_task }}</b>?</h1> <h1>Ste si istý, že chcete {{ subtask.is_finished ? 'znovu otvoriť' : 'dokončiť' }} task, z masterTasku <b>{{ subtask?.master_task?.name || subtask.master_task }}</b>?</h1>
<v-icon <v-icon
@click.stop="visible = false" @click.stop="visible = false"
icon="mdi-close" icon="mdi-close"
@@ -36,12 +36,13 @@ export default {
async complete() { async complete() {
try { try {
const tempSubtask = {...this.subtask, is_finished: !this.subtask.is_finished} const tempSubtask = {...this.subtask, is_finished: this.subtask.is_finished ? 0 : 1}
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${tempSubtask.id}`, tempSubtask) const { subtask } = await this.$axios.put_auth(`v1/subtasks/${tempSubtask.id}`, tempSubtask)
this.visible = false this.visible = false
this.$store.dispatch('tm/loadMastertasks')
this.$store.commit('tm/update_subtask', subtask) this.$store.dispatch('tm/loadUnscheduledSubtasks')
this.$store.dispatch('tm/loadOngoingSubtasks')
this.$emit('on-subtask-edited', subtask) this.$emit('on-subtask-edited', subtask)
} catch (error) { } catch (error) {
this.$toast.error(error) this.$toast.error(error)