add teacher and admin portals
This commit is contained in:
8 files changed
+160
-7
No files matched your search
@@ -17,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
logout() {
|
logout() {
|
||||||
const res = fetch(`${this.API_URL}/logout`, {
|
fetch(`${this.API_URL}/logout`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -29,10 +29,6 @@
|
|||||||
status: response.status,
|
status: response.status,
|
||||||
})).then(res => res)
|
})).then(res => res)
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (res.status != 200) // do something
|
|
||||||
|
|
||||||
if (res.data.success) this.$router.push('/');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<router-link to="/">Home</router-link>
|
||||||
<h1 style="text-transform: capitalize;">{{user}} login</h1>
|
<h1 style="text-transform: capitalize;">{{user}} login</h1>
|
||||||
<form @submit.prevent="login">
|
<form @submit.prevent="login">
|
||||||
<input v-model="uid" :placeholder="user.charAt(0).toUpperCase() + user.slice(1) + ' ID'"/>
|
<input v-model="uid" :placeholder="user.charAt(0).toUpperCase() + user.slice(1) + ' ID'"/>
|
||||||
|
|||||||
+21
-1
@@ -24,7 +24,27 @@ const routes = [
|
|||||||
path: '/student/dashboard',
|
path: '/student/dashboard',
|
||||||
name: 'studentDashboard',
|
name: 'studentDashboard',
|
||||||
component: () => import('../views/StudentDashboard.vue')
|
component: () => import('../views/StudentDashboard.vue')
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
path: '/teacher/login',
|
||||||
|
name: 'teacherLogin',
|
||||||
|
component: () => import('../views/TeacherLogin.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/teacher/dashboard',
|
||||||
|
name: 'teacherDashboard',
|
||||||
|
component: () => import('../views/TeacherDashboard.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/admin/login',
|
||||||
|
name: 'adminLogin',
|
||||||
|
component: () => import('../views/AdminLogin.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/admin/dashboard',
|
||||||
|
name: 'adminDashboard',
|
||||||
|
component: () => import('../views/AdminDashboard.vue')
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<template>
|
||||||
|
<DashboardNav />
|
||||||
|
<h1>Admin Dashboard</h1>
|
||||||
|
<UserModel v-if="admin!={}" :user="admin" :uid="admin.aid"/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import UserModel from '@/components/UserModel.vue';
|
||||||
|
import DashboardNav from '@/components/DashboardNav.vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'AdminDashboard',
|
||||||
|
components: {
|
||||||
|
UserModel,
|
||||||
|
DashboardNav,
|
||||||
|
},
|
||||||
|
data: () => {
|
||||||
|
return {
|
||||||
|
API_URL: process.env.VUE_APP_API_URL,
|
||||||
|
admin: {},
|
||||||
|
message: "", // where we store any error messages etc.
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async isAuthenticated() {
|
||||||
|
const res = await fetch(`${this.API_URL}/admin`, {
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
}).then(response =>
|
||||||
|
response.json().then(data => ({
|
||||||
|
data: data,
|
||||||
|
status: response.status,
|
||||||
|
})).then(res => res)
|
||||||
|
);
|
||||||
|
|
||||||
|
// if (!res.status == 200) // do something
|
||||||
|
|
||||||
|
if (res.data.success) {
|
||||||
|
// set local data
|
||||||
|
this.admin = res.data.result;
|
||||||
|
} else this.$router.push('/admin/login');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.isAuthenticated()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LoginComp user="admin"/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import LoginComp from '@/components/LoginComp.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'AdminLogin',
|
||||||
|
components: {
|
||||||
|
LoginComp,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<DashboardNav />
|
<DashboardNav />
|
||||||
<h1>Dashboard</h1>
|
<h1>Student Dashboard</h1>
|
||||||
<UserModel v-if="student!={}" :user="student" :photo="photo" :uid="student.School.sid"/>
|
<UserModel v-if="student!={}" :user="student" :photo="photo" :uid="student.School.sid"/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<DashboardNav />
|
||||||
|
<h1>Teacher Dashboard</h1>
|
||||||
|
<UserModel v-if="teacher!={}" :user="teacher" :photo="photo" :uid="teacher.School.tid"/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import UserModel from '@/components/UserModel.vue';
|
||||||
|
import DashboardNav from '@/components/DashboardNav.vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'TeacherDashboard',
|
||||||
|
components: {
|
||||||
|
UserModel,
|
||||||
|
DashboardNav,
|
||||||
|
},
|
||||||
|
data: () => {
|
||||||
|
return {
|
||||||
|
API_URL: process.env.VUE_APP_API_URL,
|
||||||
|
teacher: {},
|
||||||
|
photo: {},
|
||||||
|
message: "", // where we store any error messages etc.
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async isAuthenticated() {
|
||||||
|
const res = await fetch(`${this.API_URL}/teacher`, {
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
}).then(response =>
|
||||||
|
response.json().then(data => ({
|
||||||
|
data: data,
|
||||||
|
status: response.status,
|
||||||
|
})).then(res => res)
|
||||||
|
);
|
||||||
|
|
||||||
|
// if (!res.status == 200) // do something
|
||||||
|
|
||||||
|
if (res.data.success) {
|
||||||
|
// set local data
|
||||||
|
this.teacher = res.data.response.teacher;
|
||||||
|
this.photo = res.data.response.photo;
|
||||||
|
} else this.$router.push('/teacher/login');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.isAuthenticated()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LoginComp user="teacher"/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import LoginComp from '@/components/LoginComp.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'TeacherLogin',
|
||||||
|
components: {
|
||||||
|
LoginComp,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
Reference in new issue
Block a user