Untitled
raw download clone
TEXT
views 24
,
size 7642 b
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import AdminPage from '../views/Admin.vue'
import Specialist from '../views/Specialist.vue'
import Operator from '../views/Operator.vue'
import StatisticsPage from "../components/StatisticsPage";
import {auth} from '../../src/fb'
import axios from 'axios';

Vue.use(VueRouter);
var UserType;
const routes = [
  {
      path: '/',
      name: 'Login',
      component: Login,
  },

    //Routing and protection for the specialist page
  {
      path: '/Specialist',
      name: 'Specialist',
      component: Specialist,
      async beforeEnter(to, from, next) {
          try {
              var userId = auth.currentUser.uid;
          } catch {
              next({
                  name: "Login", // back to safety route //
                  query: { illegalAccess: "yes" }
              })
          }
          if (userId != null){
              axios.post("https://makeitall.mooo.com:1234/crud.php", {username: "bcgi", password:"Bdcg1pass", action: "SELECT", query: "SELECT * FROM Users WHERE User_Id ='"+auth.currentUser.uid+"'"})
                  .then(response =>{
                      UserType = response.data[0]["User_Type"];
                      try {
                          if (UserType == "Specialist") {
                              next()
                          } else {
                              next({
                                  name: "Login", // back to safety route //
                                  query: { illegalAccess: "yes" }
                              })
                          }
                      } catch (e) {
                          next({
                              name: "Login", // back to safety route //
                              query: { illegalAccess: "yes" }
                          })
                      }
                  })
          }else{
              next({
                  name: "Login", // back to safety route //
                  query: { illegalAccess: "yes" }
              })
          }
      }
  },
    //Routing and protection for the operator page
  {
      path: '/Operator',
      name: 'Operator',
      component: Operator,
      async beforeEnter(to, from, next) {
          try {
              var userId = auth.currentUser.uid;
          } catch {
              next({
                  name: "Login", // back to safety route //
                  query: { illegalAccess: "yes" }
              })
          }
          if (userId != null){
              axios.post("https://makeitall.mooo.com:1234/crud.php", {username: "bcgi", password:"Bdcg1pass", action: "SELECT", query: "SELECT * FROM Users WHERE User_Id ='"+auth.currentUser.uid+"'"})
                  .then(response =>{
                      UserType = response.data[0]["User_Type"];
                      try {
                          if (UserType == "Operator") {
                              next()
                          } else {
                              next({
                                  name: "Login", // back to safety route //
                                  query: { illegalAccess: "yes" }
                              })
                          }
                      } catch (e) {
                          next({
                              name: "Login", // back to safety route //
                              query: { illegalAccess: "yes" }
                          })
                      }
                  })
          }else{
              next({
                  name: "Login", // back to safety route //
                  query: { illegalAccess: "yes" }
              })
          }
      }
  },

    //Routing and protection for the admin page
  {
      path: '/Admin',
      name: 'Admin',
      component: AdminPage,
      async beforeEnter(to, from, next) {
          try {
              var userId = auth.currentUser.uid;
          } catch {
              next({
                  name: "Login", // back to safety route //
                  query: { illegalAccess: "yes" }
              })
          }
          if (userId != null){
              axios.post("https://makeitall.mooo.com:1234/crud.php", {username: "bcgi", password:"Bdcg1pass", action: "SELECT", query: "SELECT * FROM Users WHERE User_Id ='"+auth.currentUser.uid+"'"})
                  .then(response =>{
                      UserType = response.data[0]["User_Type"];
                      try {
                          if (UserType == "Admin") {
                              next()
                          } else {
                              next({
                                  name: "Login", // back to safety route //
                                  query: { illegalAccess: "yes" }
                              })
                          }
                      } catch (e) {
                          next({
                              name: "Login", // back to safety route //
                              query: { illegalAccess: "yes" }
                          })
                      }
                  })
          }else{
              next({
                  name: "Login", // back to safety route //
                  query: { illegalAccess: "yes" }
              })
          }
      }
  },

    //Routing and protection for the stats page
  {
        path: '/StatsPage',
        name: 'StatisticsPage',
        component: StatisticsPage,
          async beforeEnter(to, from, next) {
            try {
                var userId = auth.currentUser.uid;
            } catch {
                next({
                    name: "Login", // back to safety route //
                    query: { illegalAccess: "yes" }
                })
            }
            if (userId != null){
                axios.post("https://makeitall.mooo.com:1234/crud.php", {username: "bcgi", password:"Bdcg1pass", action: "SELECT", query: "SELECT * FROM Users WHERE User_Id ='"+auth.currentUser.uid+"'"})
                    .then(response =>{
                        UserType = response.data[0]["User_Type"];
                        try {
                            if (UserType == "Admin") {
                                next()
                            } else {
                                next({
                                    name: "Login", // back to safety route //
                                    query: { illegalAccess: "yes" }
                                })
                            }
                        } catch (e) {
                            next({
                                name: "Login", // back to safety route //
                                query: { illegalAccess: "yes" }
                            })
                        }
                    })
            }else{
                next({
                    name: "Login", // back to safety route //
                    query: { illegalAccess: "yes" }
                })
            }
          }
  },
    {
        path: '*',
        name: 'Login',
        component: Login,
        async beforeEnter(to, from, next) {
                next({
                    name: "Login", // back to safety route //
                    query: { pageNotExist: "yes" }
                })
            }
    },
];
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});

export default router
close fullscreen
Login or Register to edit or fork this paste. It's free.