-
-
-
-
-
+
@@ -55,10 +57,11 @@
-
+
-
+
+
diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js
index 4b87b13..ff91372 100644
--- a/frontend/src/router/routes.js
+++ b/frontend/src/router/routes.js
@@ -15,17 +15,23 @@ const routes = [
component: () => import("layouts/MyLayout.vue"),
children: [{ path: "", component: () => import("pages/Cache.vue") }]
},
+ {
+ path: "/cache/:id",
+ component: () => import("layouts/MyLayout.vue"),
+ children: [{ path: "", component: () => import("pages/Cache.vue") }]
+ },
{
path: "/station/",
component: () => import("layouts/MyLayout.vue"),
children: [{ path: "", component: () => import("pages/StationEdit.vue") }]
},
{
- path: "/station/:id",
+ path: "/station/:cache/:id",
component: () => import("layouts/MyLayout.vue"),
children: [{ path: "", component: () => import("pages/StationView.vue") }]
},
{
+ path: "/station-l/:pos",
path: "/ranking/",
component: () => import("layouts/MyLayout.vue"),
children: [{path: "", component: () => import("pages/ranking.vue")}]
@@ -33,15 +39,9 @@ const routes = [
{
path: "/station/",
component: () => import("layouts/MyLayout.vue"),
- // props: true,
- children: [{
- path: "",
- component: () => import("pages/StationEdit.vue"),
- // props: true
- //props: ['stationObject']
-}]
-},
-{
+ children: [{ path: "", component: () => import("pages/StationEdit.vue") }]
+ },
+ {
path: "/login/",
component: () => import("layouts/MyLayout.vue"),
children: [{ path: "", component: () => import("pages/Login.vue") }]
diff --git a/frontend/src/store/auth/getters.js b/frontend/src/store/auth/getters.js
index cc054a3..da66d9b 100644
--- a/frontend/src/store/auth/getters.js
+++ b/frontend/src/store/auth/getters.js
@@ -1,4 +1,24 @@
-/*
-export function someGetter (state) {
+/**
+ * @return {boolean}
+ */
+export function GET_ADMINSTATE(state) {
+ console.log("GET_ADMINSTATE()");
+ if (state.userAuthenticated !== null) {
+ console.log(state.userAuthenticated.roles.find(x => x.name === "admin") != null);
+ return state.userAuthenticated.roles.find(x => x.name === "admin") != null;
+ } else {
+ console.log(state.userAuthenticated);
+ return false;
+ }
}
-*/
+
+// /**
+// * @return {boolean}
+// */
+// export function IS_AUTHENTICATED(state) {
+// console.log("IS_AUTHENTICATED()");
+// console.log(JSON.parse(localStorage.getItem('userToken')));
+// console.log(!(JSON.parse(localStorage.getItem('userToken')) === null));
+// console.log(!(localStorage.getItem('userToken') === null));
+// return !(localStorage.getItem('userToken') === null);
+// }
diff --git a/frontend/src/store/auth/mutations.js b/frontend/src/store/auth/mutations.js
index 3a5c061..fed76c1 100644
--- a/frontend/src/store/auth/mutations.js
+++ b/frontend/src/store/auth/mutations.js
@@ -1,17 +1,43 @@
+import axios from 'axios'
export const SET_AUTHENTICATED = (state) => {
console.log("SET_AUTHENTICATED()");
console.log(JSON.parse(localStorage.getItem('userToken')));
if (localStorage.getItem('userToken')) {
- state.userAuthenticated.isAuthenticated = true;
+ state.isAuthenticated = true;
} else {
- state.userAuthenticated.isAuthenticated = false;
+ state.isAuthenticated = false;
}
};
-export const SET_USER_PROPERTIES = (state, user) => {
- console.log("SET_USER_PROPERTIES()");
- console.log("still todo!");
-};
export const SET_LOGOUT = (state) => {
console.log("SET_LOGOUT()");
+ localStorage.removeItem('userToken');
state.userAuthenticated = null;
+ state.isAuthenticated = false;
+ console.log(localStorage.getItem('userToken'));
};
+export const SET_USER = (state) => {
+ console.log("SET_USER()");
+ if (localStorage.getItem('userToken')) {
+ axios.get('http://localhost:8080/api/getUser', {
+ params: {
+ token: JSON.parse(localStorage.getItem('userToken'))
+ }
+ })
+ .then((response) => {
+ console.log("GET/POST http://localhost:8080/api/getUser - response: ");
+ console.log(response.data);
+ state.userAuthenticated = response.data;
+ state.isAuthenticated = true;
+ if (state.userAuthenticated.hasOwnProperty('password')) delete state.userAuthenticated.password;
+ console.log(state.userAuthenticated);
+ })
+ .catch((error) => {
+ console.log("Catch Block: ")
+ console.log(error)
+ });
+ } else {
+ state.isAuthenticated = false;
+ state.userAuthenticated = null;
+ }
+};
+
diff --git a/frontend/src/store/auth/state.js b/frontend/src/store/auth/state.js
index 1fee418..902a77e 100644
--- a/frontend/src/store/auth/state.js
+++ b/frontend/src/store/auth/state.js
@@ -1,12 +1,19 @@
export default {
- userAuthenticated: {
- id: 1,
- firstname: "t",
- lastname: "v",
- username: "mo",
- email: "test@user.com",
- rankingPointsSum: 345,
- isAuthenticated: false,
- isAdmin: true,
- },
+ isAuthenticated: false,
+ userAuthenticated: null,
+ // userAuthenticated: {
+ // id: 1,
+ // firstname: "Timo",
+ // lastname: "Volkmann",
+ // username: "moximoti",
+ // rankingPointsSum: 0,
+ // email: "test@user.com",
+ // password: "$2a$10$c3Fo5nuUG.nlwXP94qc7qO01/UC1OL2DebEm.5zYlisKJGRhXMnqq",
+ // roles: [
+ // {
+ // id: 0,
+ // name: "admin"
+ // }
+ // ]
+ // },
}
diff --git a/frontend/src/store/cacheCollector/mutations.js b/frontend/src/store/cacheCollector/mutations.js
index ee2cab7..646ab0f 100644
--- a/frontend/src/store/cacheCollector/mutations.js
+++ b/frontend/src/store/cacheCollector/mutations.js
@@ -10,17 +10,20 @@ export const ADD_STATION = (state, station) => {
console.log("ADD_STATION: add new station to cache: "+station);
state.newCache.stationen.push(station);
};
-export const EDIT_STATION = (state, index, station) => {
- console.log("ADD_STATION: add new station to cache: "+station);
+export const EDIT_STATION = (state, indexStation) => {
+ let index, station;
+ index = indexStation.index;
+ station = indexStation.station;
+ console.log("EDIT_STATION: "+index+" "+station);
+
state.newCache.stationen[index] = station;
};
export const REMOVE_STATION = (state, index) => {
- console.log("ADD_STATION: add new station to cache: "+station);
+ console.log("REMOVE_STATION: "+index);
state.newCache.stationen.splice(index,1);
};
export const RESET_NEW_CACHE = (state) => {
state.newCache = {
- id: null,
name: "",
description: "",
rankingPoints: 0,
diff --git a/frontend/src/store/cacheCollector/state.js b/frontend/src/store/cacheCollector/state.js
index 3836b13..7087a3a 100644
--- a/frontend/src/store/cacheCollector/state.js
+++ b/frontend/src/store/cacheCollector/state.js
@@ -1,38 +1,44 @@
export default {
newCache: {
- name: "Blumencache",
- description: "Dieser Cache umfasst 4 Stationen mit Rätseln rund um das Thema Blumen",
- rankingPoints: 100,
- stationen: [
- {
- description: "Ein kleines winterliches Schlaginstrument. Welche Blume ist damit gemeint?",
- longitude: 9.206628,
- lattitude: 49.147734,
- code: 213812,
- solution: "Schneeglöckchen"
- },
- {
- description: "Ein blühendes Federvieh. Welche Blume ist damit gemeint?",
- longitude: 9.206806,
- lattitude: 49.147318,
- code: 237823,
- solution: "Gänseblümchen"
- },
- {
- description: "Eine wertvolle Farbe. Welche Blume ist damit gemeint?",
- longitude: 9.207844,
- lattitude: 49.148032,
- code: 899423,
- solution: "Edelweiß"
- },
- {
- description: "Ein Zerkleinerungsgerät in der Brüllöffnung eines Raubtieres. Welche Blume ist damit gemeint?",
- longitude: 9.207649,
- lattitude: 49.150142,
- code: 347923,
- solution: "Löwenzahn"
- }
- ]
+ name: "",
+ description: "",
+ rankingPoints: 0,
+ stationen: []
},
+ // newCache: {
+ // name: "Blumencache",
+ // description: "Dieser Cache umfasst 4 Stationen mit Rätseln rund um das Thema Blumen",
+ // rankingPoints: 100,
+ // stationen: [
+ // {
+ // description: "Ein kleines winterliches Schlaginstrument. Welche Blume ist damit gemeint?",
+ // longitude: 9.206628,
+ // lattitude: 49.147734,
+ // code: 213812,
+ // solution: "Schneeglöckchen"
+ // },
+ // {
+ // description: "Ein blühendes Federvieh. Welche Blume ist damit gemeint?",
+ // longitude: 9.206806,
+ // lattitude: 49.147318,
+ // code: 237823,
+ // solution: "Gänseblümchen"
+ // },
+ // {
+ // description: "Eine wertvolle Farbe. Welche Blume ist damit gemeint?",
+ // longitude: 9.207844,
+ // lattitude: 49.148032,
+ // code: 899423,
+ // solution: "Edelweiß"
+ // },
+ // {
+ // description: "Ein Zerkleinerungsgerät in der Brüllöffnung eines Raubtieres. Welche Blume ist damit gemeint?",
+ // longitude: 9.207649,
+ // lattitude: 49.150142,
+ // code: 347923,
+ // solution: "Löwenzahn"
+ // }
+ // ]
+ // },
tempStation: {},
}
diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js
index 8eb6c71..0ce2a96 100644
--- a/frontend/src/store/index.js
+++ b/frontend/src/store/index.js
@@ -22,7 +22,8 @@ export default function (/* { ssrContext } */) {
// enable strict mode (adds overhead!)
// for dev mode only
- strict: process.env.DEV
+ //strict: process.env.DEV
+ strict: false
})
/*
diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
index a97359a..397ef33 100644
--- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
+++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.PostConstruct;
import javax.xml.bind.DatatypeConverter;
+import java.lang.reflect.Array;
import java.security.Key;
import java.security.SecureRandom;
import java.util.*;
@@ -126,7 +127,6 @@ public class Controller {
.setSigningKey(key)
.parseClaimsJws(token).getBody();
-
User user = userRepository.findByUsername(claims.getSubject());
if (user == null) {
return ResponseEntity.status(404).body("User was not found");
@@ -136,29 +136,35 @@ public class Controller {
Optional
cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID));
if (cacheOptional.isPresent()) {
Cache cache = cacheOptional.get();
+
+ if (bearbeitetRepository.findByUserAndCache(user, cache) != null) {
+ Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache);
+ return ResponseEntity.status(200).body(bearbeitet1);
+ }
+
bearbeitet.setCache(cache);
- Station startStation = cache.getStationen().get(0);
- bearbeitet.setAktuelleStation(startStation);
- } else {
- return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID);
- }
+ Station startStation = cache.getStationen().get(0);
+ bearbeitet.setAktuelleStation(startStation);
+ } else {
+ return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID);
+ }
- Optional cacheAccesDefinitionOptional =
- cacheAccesDefinitionRepository.findById(0); // angefangen
- if (cacheAccesDefinitionOptional.isPresent()) {
- CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
- bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
- } else {
- return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0);
- }
+ Optional cacheAccesDefinitionOptional =
+ cacheAccesDefinitionRepository.findById(0); // angefangen
+ if (cacheAccesDefinitionOptional.isPresent()) {
+ CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
+ bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
+ } else {
+ return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0);
+ }
bearbeitetRepository.save(bearbeitet);
- return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet));
+ return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet));
} catch (ExpiredJwtException e) {
return ResponseEntity.status(400).body("JWT Token expired");
- } catch (Exception e){
+ } catch (Exception e) {
return ResponseEntity.status(400).body("JWT Token invalid");
}
@@ -194,7 +200,9 @@ public class Controller {
@RequestMapping("/api/createCache")
@ResponseBody
public ResponseEntity createCache(@RequestBody Cache cache) {
-
+ System.out.println(cache.getName());
+ System.out.println(cache.getStationen().size());
+// System.out.println(cache.getStationen().get(0).getId());
// Stationen werden in die Datenbank eingetragen
for (Station station : cache.getStationen()) {
ResponseEntity response = createStation(station);
@@ -203,9 +211,9 @@ public class Controller {
return response;
}
}
-
+ System.out.println("Stationen eingetragen!");
// Caches werden in die Datenbank eingetragen
- if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0 || cache.getStationen().size() == 0) {
+ if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0 || cache.getStationen().size() < 2) {
deleteStationen(cache);
return ResponseEntity.status(400).body("cache fields can´t be empty");
}
@@ -229,7 +237,7 @@ public class Controller {
public ResponseEntity createStation(Station station) {
- if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 || station.getSolution().length() == 0) {
+ if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 /*|| station.getSolution().length() == 0*/) {
return ResponseEntity.status(400).body("station fields can´t be empty");
}
@@ -285,9 +293,9 @@ public class Controller {
.parseClaimsJws(token).getBody();
return ResponseEntity.status(200).body(claims.get("admin"));
- }catch (ExpiredJwtException e) {
+ } catch (ExpiredJwtException e) {
return ResponseEntity.status(400).body("JWT Token expired");
- } catch (Exception e){
+ } catch (Exception e) {
return ResponseEntity.status(400).body("JWT Token invalid");
}
@@ -328,8 +336,18 @@ public class Controller {
}
}
+ ArrayList stationen = new ArrayList<>();
+ for (Station station : cache.getStationen()) {
+ stationen.add(stationRepository.findById(station.getId()).get());
+ }
+
cacheRepository.delete(cache);
+ for (Station station : stationen) {
+ stationRepository.delete(station);
+ }
+
+
return ResponseEntity.status(200).body(new Gson().toJson(true));
}
@@ -360,7 +378,7 @@ public class Controller {
}
} catch (ExpiredJwtException e) {
return ResponseEntity.status(400).body("JWT Token expired");
- } catch (Exception e){
+ } catch (Exception e) {
return ResponseEntity.status(400).body("JWT Token invalid");
}
}
@@ -401,7 +419,7 @@ public class Controller {
}
} catch (ExpiredJwtException e) {
return ResponseEntity.status(400).body("JWT Token expired");
- } catch (Exception e){
+ } catch (Exception e) {
return ResponseEntity.status(400).body("JWT Token invalid");
}
}
diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java
index ac5484c..4b5c1a0 100644
--- a/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java
+++ b/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java
@@ -1,8 +1,11 @@
package hhn.labsw.bugageocaching.repositories;
import hhn.labsw.bugageocaching.entities.Bearbeitet;
+import hhn.labsw.bugageocaching.entities.Cache;
+import hhn.labsw.bugageocaching.entities.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
public interface BearbeitetRepository extends JpaRepository {
+ Bearbeitet findByUserAndCache(User user, Cache cache);
}