@@ -120,7 +120,8 @@
.then((response) => {
console.log(response.data);
if(response.status === 201){
- this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: "Deine Registrierung war erfolgreich!", title: "Registrierungsprozess", color: "blue"});
+ this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: "Deine Registrierung war erfolgreich! Du kannst dich jetzt einloggen.", title: "Registrierungsprozess", color: "blue"});
+ this.$router.push("/login")
}
})
.catch((error) => {
diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js
index 8c7a194..713eb99 100644
--- a/frontend/src/router/index.js
+++ b/frontend/src/router/index.js
@@ -2,25 +2,86 @@ import Vue from "vue";
import VueRouter from "vue-router";
import routes from "./routes";
-
+import {axiosInstance} from "../boot/axios";
Vue.use(VueRouter);
+//import store from "../store/index";
+
/*
* If not building with SSR mode, you can
* directly export the Router instantiation
*/
-export default function(/* { store, ssrContext } */) {
+export default function({ store }/* { store, ssrContext } */) {
const Router = new VueRouter({
scrollBehavior: () => ({ x: 0, y: 0 }),
routes,
-
+ store,
// Leave these as is and change from quasar.conf.js instead!
// quasar.conf.js -> build -> vueRouterMode
// quasar.conf.js -> build -> publicPath
mode: process.env.VUE_ROUTER_MODE,
base: process.env.VUE_ROUTER_BASE
});
+ Router.beforeEach((to, from, next) => {
+ console.log("before Routing...");
+ const isPublic = to.matched.some(record => record.meta.public);
+ const onlyWhenLoggedOut = to.matched.some(record => record.meta.onlyWhenLoggedOut);
+ const onlyAdmin = to.matched.some(record => record.meta.onlyAdmin);
+ const loggedIn = localStorage.getItem('userToken')
+ ? JSON.parse(localStorage.getItem('userToken'))
+ : false;
+ console.log(`isPublic: ${isPublic} \nonlyWhenLoggedOut: ${onlyWhenLoggedOut} \nonlyAdmin: ${onlyAdmin}`);
+ console.log("loggedIn");
+ console.log(loggedIn);
+ const isAdmin = loggedIn ? loggedIn.roles.find(x => x.role === "ADMIN" && x.domain === "geocaching.de") : false;
+ //const isAdmin = true;
+ if (!isPublic && !loggedIn) {
+ return next({
+ path:'/login',
+ query: {redirect: to.fullPath} // Store the full path to redirect the user to after login
+ });
+ }
+ if ((loggedIn && onlyWhenLoggedOut) || (loggedIn && onlyAdmin && !isAdmin)) {
+ return next('/')
+ }
+ if (isPublic) {
+ return next()
+ }
+ if (!isPublic && loggedIn) {
+ axiosInstance.get('/api/getUser', {
+ params: {
+ token: loggedIn.token
+ }
+ })
+ .then((response) => {
+ console.log("Token valid!");
+ return next();
+ })
+ .catch((error) => {
+ console.log("Catch Block: ");
+ console.log("Token invalid!");
+ if (error.response) {
+ console.log(error.response.data);
+ console.log(error.response.status);
+ console.log(error.response.headers);
+ //store.commit('auth/SET_LOGOUT');
+ store.commit('dialog/NEW_MESSAGE_DIALOG', {
+ message: "Ihr Token ist nicht mehr gültig. Bitte loggen Sie sich erneut ein.",
+ title: "Bitte erneut anmelden.",
+ color: "blue", });
+ localStorage.removeItem('userToken');
+ return next('/Login');
+ } else {
+ console.log("unexpected behaviour");
+ console.log(error);
+ return next();
+ }
+ });
+ }
+ console.log(`isPublic: ${isPublic} \nonlyWhenLoggedOut: ${onlyWhenLoggedOut} \nonlyAdmin: ${onlyAdmin}`);
+ //return next();
+ });
return Router;
}
diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js
index 6a39f45..5036bab 100644
--- a/frontend/src/router/routes.js
+++ b/frontend/src/router/routes.js
@@ -2,88 +2,173 @@ const routes = [
{
path: "/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/Index.vue") }]
+ children: [{ path: "", component: () => import("pages/Index.vue") }],
+ meta: {
+ public: true, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/overview/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/Overview.vue") }]
+ children: [{ path: "", component: () => import("pages/Overview.vue") }],
+ meta: {
+ public: true, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/cache/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/Cache.vue") }]
+ children: [{ path: "", component: () => import("pages/Cache.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: true,
+ }
},
{
path: "/qr-scanner/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/qr-scanner.vue") }]
+ children: [{ path: "", component: () => import("pages/qr-scanner.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/cache/:id",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/Cache.vue") }]
+ children: [{ path: "", component: () => import("pages/Cache.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: true,
+ }
},
{
path: "/station/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/StationEdit.vue") }]
+ children: [{ path: "", component: () => import("pages/StationEdit.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: true,
+ }
},
{
path: "/endstation/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/StationEndEdit.vue") }]
+ children: [{ path: "", component: () => import("pages/StationEndEdit.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: true,
+ }
},
{
path: "/tempstation/:pos",
component: () => import("layouts/MyLayout.vue"),
- children: [{path: "", component: () => import("pages/StationEdit.vue")}]
+ children: [{path: "", component: () => import("pages/StationEdit.vue")}],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: true,
+ }
},
{
path: "/tempendstation/",
component: () => import("layouts/MyLayout.vue"),
- children: [{path: "", component: () => import("pages/StationEndEdit.vue")}]
+ children: [{path: "", component: () => import("pages/StationEndEdit.vue")}],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: true,
+ }
},
{
path: "/station/:cache/:id",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/StationView.vue") }]
+ children: [{ path: "", component: () => import("pages/StationView.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/ranking/",
component: () => import("layouts/MyLayout.vue"),
- children: [{path: "", component: () => import("pages/ranking.vue")}]
+ children: [{path: "", component: () => import("pages/ranking.vue")}],
+ meta: {
+ public: true, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/login/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/Login.vue") }]
+ children: [{ path: "", component: () => import("pages/Login.vue") }],
+ meta: {
+ public: true, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/CacheStart/:cache/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/CacheStart.vue") }]
+ children: [{ path: "", component: () => import("pages/CacheStart.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/CacheEnd/:cache/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/CacheEnd.vue") }]
+ children: [{ path: "", component: () => import("pages/CacheEnd.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/profile/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/Profile.vue") }]
+ children: [{ path: "", component: () => import("pages/Profile.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/mycaches/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/MyCaches.vue") }]
+ children: [{ path: "", component: () => import("pages/MyCaches.vue") }],
+ meta: {
+ public: false, // Allow access to even if not logged in
+ onlyWhenLoggedOut: false,
+ onlyAdmin: false,
+ }
},
{
path: "/register/",
component: () => import("layouts/MyLayout.vue"),
- children: [{ path: "", component: () => import("pages/Register.vue") }]
+ children: [{ path: "", component: () => import("pages/Register.vue") }],
+ meta: {
+ public: true, // Allow access to even if not logged in
+ onlyWhenLoggedOut: true,
+ onlyAdmin: false,
+ }
}
];
diff --git a/frontend/src/store/dialog/mutations.js b/frontend/src/store/dialog/mutations.js
index 4a14ffa..c9c7306 100644
--- a/frontend/src/store/dialog/mutations.js
+++ b/frontend/src/store/dialog/mutations.js
@@ -14,16 +14,19 @@ export function NEW_MESSAGE_DIALOG (state, messageObject) {
let color = "red-9";
state.dialog.colorBackground = "bg-"+color+" text-white";
state.dialog.colorButton = color;
+ break;
}
case "amber": {
let color = "amber";
state.dialog.colorBackground = "bg-"+color+" text-white";
state.dialog.colorButton = color;
+ break;
}
case "blue": {
let color = "primary";
state.dialog.colorBackground = "bg-"+color+" text-white";
state.dialog.colorButton = color;
+ break;
}
}
}