From fee5f4319dd0bec7d1e497651688703215cefe65 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Tue, 2 Apr 2019 23:28:27 +0200 Subject: [PATCH 01/16] Implemented: startCache Call and logout Call, some improvements in controller --- frontend/quasar.conf.js | 2 +- frontend/src/pages/Login.vue | 27 ++++++++++++++----- frontend/src/pages/Overview.vue | 17 ++++++++++-- .../bugageocaching/controller/Controller.java | 9 +++++-- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index 0528ca8..b65a837 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -103,7 +103,7 @@ module.exports = function (ctx) { devServer: { // https: true, port: 8081, - open: true // opens browser window automatically + open: false // opens browser window automatically }, // animations: 'all' --- includes all animations diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 13c0770..0cc9f9b 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -100,7 +100,8 @@ .then((response) => { console.log("GET/POST http://localhost:8080/api/login/ - response: " + response.data); //this.user.token = response.data; - localStorage.setItem('userToken', JSON.stringify(response)); + localStorage.setItem('userToken', JSON.stringify(response.data)); + //localStorage.setItem('userToken', response.data); this.isAuthenticated(); }) .catch((error) => { @@ -110,7 +111,8 @@ }, isAuthenticated: function () { console.log("isAuthenticated()"); - console.log(localStorage.getItem('userToken')); + console.log("content of localstorage: "); + console.log(JSON.parse(localStorage.getItem('userToken'))); if (localStorage.getItem('userToken')) { // TODO hier muss Abfrage mit API, z.B. /api/user?token="ME" stattfinden. this.user.isAuthenticated = true; } else { @@ -119,10 +121,23 @@ }, logout: function () { console.log("logout()"); - console.log(localStorage.getItem('userToken')); - localStorage.removeItem('userToken'); - console.log(localStorage.getItem('userToken')); - this.isAuthenticated() + console.log(JSON.parse(localStorage.getItem('userToken'))); + this.$axios.get('http://localhost:8080/api/logout', { + params: { + token: JSON.parse(localStorage.getItem('userToken')) + } + }) + .then((response) => { + console.log("GET/POST http://localhost:8080/api/logout/ - response: " + response.data); + localStorage.removeItem('userToken'); + this.isAuthenticated(); + }) + .catch((error) => { + }); + // console.log(localStorage.getItem('userToken')); + // localStorage.removeItem('userToken'); + // console.log(localStorage.getItem('userToken')); + // this.isAuthenticated() }, }, }; diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 5295f00..8efbcda 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -50,7 +50,7 @@ - + @@ -76,7 +76,7 @@ export default { data() { return { - tab: 'map', + tab: 'list', hheight: 71.0, fheight: 36.0, //37 //header: {h: '0px', w: 0} @@ -111,6 +111,19 @@ console.log("Caches: " + this.caches); this.caches = response.data; }) + }, + startCache(cacheID) { + const userToken = JSON.parse(localStorage.getItem('userToken')); + let params = { cacheID: cacheID }; + if (userToken != null) { + params.token = userToken; + } + console.log(params); + + this.$axios.get('http://localhost:8080/api/startCache', { params }) + .then((response) => { + console.log("Angefangen: " + response.data); + }) } } } diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index a245f13..a79e8ed 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -71,7 +71,8 @@ public class Controller { String hashedToken = BCrypt.hashpw(token, BCrypt.gensalt()); userRepository.findByUsername(user.getUsername()).setToken(hashedToken); userRepository.save(userRepository.findByUsername(user.getUsername())); - return ResponseEntity.ok(new Gson().toJson(token)); + //return ResponseEntity.ok(new Gson().toJson(token)); + return ResponseEntity.ok(token); } return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(null); } @@ -128,8 +129,12 @@ public class Controller { @RequestMapping("/api/logout") @ResponseBody boolean logout(@RequestParam String token) { - +// System.out.println("logout"); User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); +// System.out.println(token); +// System.out.println(user.getToken()); + if (user == null || user.getToken().isEmpty() ) + return false; user.setToken(null); userRepository.save(user); return true; From 0f7a4a56e6a57d3b10f16914545a6b23425fd994 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Thu, 4 Apr 2019 10:25:11 +0200 Subject: [PATCH 02/16] added view for Stations --- frontend/quasar.conf.js | 1 + frontend/src/pages/Login.vue | 7 +--- frontend/src/pages/Overview.vue | 49 ++++++++++++++------------- frontend/src/pages/Station.vue | 60 +++++++++++++++++++++++++++++++++ frontend/src/router/routes.js | 10 ++++++ 5 files changed, 97 insertions(+), 30 deletions(-) create mode 100644 frontend/src/pages/Station.vue diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index b65a837..42861b5 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -63,6 +63,7 @@ module.exports = function (ctx) { 'QSpinnerPuff', 'QExpansionItem', 'QParallax', + 'QEditor', ], directives: [ diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 0cc9f9b..c5d83e3 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -82,7 +82,6 @@ // }, mounted () { this.isAuthenticated(); - //this.pollData(); console.log("mounted: initiated"); }, methods: { @@ -113,7 +112,7 @@ console.log("isAuthenticated()"); console.log("content of localstorage: "); console.log(JSON.parse(localStorage.getItem('userToken'))); - if (localStorage.getItem('userToken')) { // TODO hier muss Abfrage mit API, z.B. /api/user?token="ME" stattfinden. + if (localStorage.getItem('userToken')) { this.user.isAuthenticated = true; } else { this.user.isAuthenticated = false; @@ -134,10 +133,6 @@ }) .catch((error) => { }); - // console.log(localStorage.getItem('userToken')); - // localStorage.removeItem('userToken'); - // console.log(localStorage.getItem('userToken')); - // this.isAuthenticated() }, }, }; diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 8efbcda..b7ff5ad 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -9,26 +9,16 @@ active-bg-color="bg-grey-1" active-color="cyan-14" indicator-color="cyan-14" - narrow-indicator switch-indicator > - +
- - - - - - - @@ -41,7 +31,7 @@ - {{ cache.name }} + {{ cache.name }} {{ cache.rankingPoints }} Punkte / Size {{ cache.stationen.length }} @@ -57,6 +47,18 @@ + + + + + + + + + +
@@ -70,15 +72,14 @@ */ + + diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js index 46da100..c027592 100644 --- a/frontend/src/router/routes.js +++ b/frontend/src/router/routes.js @@ -19,6 +19,16 @@ const routes = [ component: () => import("layouts/MyLayout.vue"), children: [{ path: "", component: () => import("pages/CacheView.vue") }] }, + { + path: "/station/", + component: () => import("layouts/MyLayout.vue"), + children: [{ path: "", component: () => import("pages/Station.vue") }] + }, + { + path: "/station/:id", + component: () => import("layouts/MyLayout.vue"), + children: [{ path: "", component: () => import("pages/Station.vue") }] + }, { path: "/login/", component: () => import("layouts/MyLayout.vue"), From cd3508090b3a552cadef461b4c0c5d046e5fd73a Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 4 Apr 2019 12:16:26 +0200 Subject: [PATCH 03/16] added getUser API method --- .../bugageocaching/controller/Controller.java | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index a245f13..2e761c1 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -290,23 +290,39 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getMyCaches") @ResponseBody - String getMyCaches(@RequestParam String token) { - User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); - ArrayList bearbeitetList = new ArrayList<>(); + ResponseEntity getMyCaches(@RequestParam String token) { + try { + User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); + ArrayList bearbeitetList = new ArrayList<>(); - for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) { - if (bearbeitet.getUser().getId() == user.getId()) { - bearbeitetList.add(bearbeitet); + for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) { + if (bearbeitet.getUser().getId() == user.getId()) { + bearbeitetList.add(bearbeitet); + } } + return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList)); + } catch (Exception e) { + return ResponseEntity.status(404).body("User was not found in the database"); } - return new Gson().toJson(bearbeitetList); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getRankingList") @ResponseBody - String getRankingList() { - return new Gson().toJson(userRepository.getRankingList()); + ResponseEntity getRankingList() { + return ResponseEntity.status(200).body(new Gson().toJson(userRepository.getRankingList())); + } + + @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose + @RequestMapping("/api/getUser") + @ResponseBody + ResponseEntity getUser(@RequestParam String token) { + try { + User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); + return ResponseEntity.status(200).body(new Gson().toJson(user)); + } catch (Exception e) { + return ResponseEntity.status(404).body("User was not found in the database"); + } } } From 2a459818f2ee8235ee92ee64f72be43b820e3089 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Thu, 4 Apr 2019 15:00:53 +0200 Subject: [PATCH 04/16] some changes --- frontend/src/pages/Overview.vue | 23 ++++++++++++++--------- frontend/src/pages/Station.vue | 3 +-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index b7ff5ad..f9285c7 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -24,27 +24,32 @@ + - + - {{ cache.name }} - - {{ cache.rankingPoints }} Punkte / - Size {{ cache.stationen.length }} - - {{ cache.description.substring(0,80) }} ... + {{ cache.description }} - + + + + - diff --git a/frontend/src/pages/Station.vue b/frontend/src/pages/Station.vue index d4f3032..61c7d06 100644 --- a/frontend/src/pages/Station.vue +++ b/frontend/src/pages/Station.vue @@ -19,8 +19,7 @@ src="https://www.buga2019.de/we-bilder/3.Gartenausstellung/Gelaendeplan/190320_Gelaendeplan-quadratisch.jpg" >
- - +
From 072a1f286d67b1a7a2a0d472cab09b267c548082 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 4 Apr 2019 15:03:01 +0200 Subject: [PATCH 05/16] reworked methods to return a http response --- .../bugageocaching/controller/Controller.java | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 2e761c1..6bcd08c 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -67,7 +67,6 @@ public class Controller { if (BCrypt.checkpw(user.getPassword(), userRepository.findByUsername(user.getUsername()).getPassword())) { String token = user.getUsername() + BCrypt.hashpw(String.valueOf(System.currentTimeMillis() + counter.incrementAndGet()), BCrypt.gensalt()); - System.out.println(token); String hashedToken = BCrypt.hashpw(token, BCrypt.gensalt()); userRepository.findByUsername(user.getUsername()).setToken(hashedToken); userRepository.save(userRepository.findByUsername(user.getUsername())); @@ -201,26 +200,26 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getAllStations") @ResponseBody - String getAllStations() { - return new Gson().toJson(stationRepository.findAll()); + ResponseEntity getAllStations() { + return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll())); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/createCache") @ResponseBody - String createCache(@RequestParam String description, - @RequestParam String name, - @RequestParam String rankingPoints, - @RequestParam(value = "rewardID", defaultValue = "-1") String rewardID, - @RequestParam List stationen) throws IllegalParameterException { + ResponseEntity createCache(@RequestParam String description, + @RequestParam String name, + @RequestParam String rankingPoints, + @RequestParam(value = "rewardID", defaultValue = "-1") String rewardID, + @RequestParam List stationen) throws IllegalParameterException { if (description.length() == 0 || name.length() == 0 || rankingPoints.length() == 0 || stationen.size() == 0) { - throw new IllegalParameterException("Fields can´t be empty"); + return ResponseEntity.status(400).body("Fields can´t be empty"); } for (Cache cache : cacheRepository.findAll()) { if (cache.getName().equals(name)) { - throw new IllegalParameterException("name is already taken"); + return ResponseEntity.status(400).body("name is already taken"); } } @@ -229,10 +228,10 @@ public class Controller { try { points = Integer.valueOf(rankingPoints); if (points < 0) { - throw new IllegalParameterException("Ranking points has to be a positive number"); + return ResponseEntity.status(400).body("Ranking points has to be a positive number"); } } catch (NumberFormatException e) { - throw new NumberFormatException("Ranking points has to be an integer"); + return ResponseEntity.status(400).body("Ranking points has to be an integer"); } Optional rewardOptional = rewardRepository.findById(Integer.valueOf(rewardID)); @@ -256,16 +255,16 @@ public class Controller { stationReihenfolgeRepository.save(stationReihenfolge); } - return new Gson().toJson(cache); + return ResponseEntity.status(200).body(new Gson().toJson(cache)); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/deleteCache") @ResponseBody - boolean deleteCache(@RequestParam String cacheID) throws IllegalParameterException { + ResponseEntity deleteCache(@RequestParam String cacheID) { Optional optionalCache = cacheRepository.findById(Integer.valueOf(cacheID)); if (!optionalCache.isPresent()) { - throw new IllegalParameterException("There is no cache with the ID " + cacheID); + return ResponseEntity.status(404).body(new Gson().toJson("There is no cache with the ID " + cacheID)); } Cache cache = optionalCache.get(); @@ -284,7 +283,7 @@ public class Controller { cacheRepository.delete(cache); - return true; + return ResponseEntity.status(200).body(new Gson().toJson(true)); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @@ -293,16 +292,20 @@ public class Controller { ResponseEntity getMyCaches(@RequestParam String token) { try { User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); - ArrayList bearbeitetList = new ArrayList<>(); + if (user != null) { + ArrayList bearbeitetList = new ArrayList<>(); - for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) { - if (bearbeitet.getUser().getId() == user.getId()) { - bearbeitetList.add(bearbeitet); + for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) { + if (bearbeitet.getUser().getId() == user.getId()) { + bearbeitetList.add(bearbeitet); + } } + return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList)); + } else { + return ResponseEntity.status(404).body("User was not found in the database"); } - return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList)); - } catch (Exception e) { - return ResponseEntity.status(404).body("User was not found in the database"); + } catch (StringIndexOutOfBoundsException e) { + return ResponseEntity.status(400).body("Invalid token"); } } @@ -319,9 +322,13 @@ public class Controller { ResponseEntity getUser(@RequestParam String token) { try { User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); - return ResponseEntity.status(200).body(new Gson().toJson(user)); - } catch (Exception e) { - return ResponseEntity.status(404).body("User was not found in the database"); + if (user != null) { + return ResponseEntity.status(200).body(new Gson().toJson(user)); + } else { + return ResponseEntity.status(404).body("User was not found in the database"); + } + } catch (StringIndexOutOfBoundsException e) { + return ResponseEntity.status(400).body("Invalid token"); } } } From ebd05f2be9a663739b083bcc67d8db0944a247c5 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Thu, 4 Apr 2019 16:07:59 +0200 Subject: [PATCH 06/16] Added Repsoneentities for Api Request --- .../bugageocaching/controller/Controller.java | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index e850b57..8992e4a 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -48,8 +48,8 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/allCaches") @ResponseBody - public String getAllCaches() { - return new Gson().toJson(cacheRepository.findAll()); + public ResponseEntity getAllCaches() { + return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll())); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @@ -59,10 +59,10 @@ public class Controller { if (user.getUsername() == null || user.getPassword() == null) { System.out.println(user.getUsername()); System.out.println(user.getPassword()); - return ResponseEntity.status(401).body(null); + return ResponseEntity.status(400).body("Username or password cant be null"); } if (userRepository.findByUsername(user.getUsername()) == null) { - return ResponseEntity.status(401).body(null); + return ResponseEntity.status(404).body("User was not found"); } if (BCrypt.checkpw(user.getPassword(), userRepository.findByUsername(user.getUsername()).getPassword())) { @@ -71,22 +71,25 @@ public class Controller { userRepository.findByUsername(user.getUsername()).setToken(hashedToken); userRepository.save(userRepository.findByUsername(user.getUsername())); //return ResponseEntity.ok(new Gson().toJson(token)); - return ResponseEntity.ok(token); + return ResponseEntity.status(200).body(token); } - return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(null); + return ResponseEntity.status(400).body("Es ist ein Fehler aufgetreten"); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/startCache") @ResponseBody - public String startCache(@RequestParam(value = "token", defaultValue = "-1") String token, - @RequestParam String cacheID) throws IllegalParameterException { + public ResponseEntity startCache(@RequestParam(value = "token", defaultValue = "-1") String token, + @RequestParam String cacheID) throws IllegalParameterException { if (!token.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben) Bearbeitet bearbeitet = new Bearbeitet(); User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); + if (user == null) { + return ResponseEntity.status(404).body("User was not found"); + } bearbeitet.setUser(user); Optional cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID)); @@ -97,7 +100,7 @@ public class Controller { Station startStation = cache.getStartStation(); bearbeitet.setAktuelleStation(startStation); } else { - throw new IllegalParameterException("There is no cache with the ID " + cacheID); + return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID); } Optional cacheAccesDefinitionOptional = @@ -111,15 +114,15 @@ public class Controller { bearbeitetRepository.save(bearbeitet); - return new Gson().toJson(bearbeitet); + return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet)); } else { // kein angemeldeter User startet den cache(es wird nur der cache als parameter übergeben) Optional cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID)); if (cacheOptional.isPresent()) { Cache cache = cacheOptional.get(); - return new Gson().toJson(cache); + return ResponseEntity.status(200).body(new Gson().toJson(cache)); } else { - throw new IllegalParameterException("There is no cache with the ID " + cacheID); + return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID); } } } @@ -127,28 +130,29 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/logout") @ResponseBody - boolean logout(@RequestParam String token) { + ResponseEntity logout(@RequestParam String token) { // System.out.println("logout"); User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); // System.out.println(token); // System.out.println(user.getToken()); - if (user == null || user.getToken().isEmpty() ) - return false; + if (user == null || user.getToken().isEmpty()) { + return ResponseEntity.status(404).body("User was not found"); + } user.setToken(null); userRepository.save(user); - return true; + return ResponseEntity.status(200).body("Token was deleted"); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/createStation") @ResponseBody - String createStation(@RequestParam String description, - @RequestParam String lattitude, - @RequestParam String longitude, - @RequestParam String solution) throws IllegalParameterException { + ResponseEntity createStation(@RequestParam String description, + @RequestParam String lattitude, + @RequestParam String longitude, + @RequestParam String solution) throws IllegalParameterException { if (description.length() == 0 || lattitude.length() == 0 || longitude.length() == 0 || solution.length() == 0) { - throw new IllegalParameterException("Fields can´t be empty"); + return ResponseEntity.status(400).body("At least one Argument was empty"); } double latti; @@ -157,19 +161,19 @@ public class Controller { try { latti = Double.valueOf(lattitude); if (latti < -90 || latti > 90) { - throw new IllegalParameterException("Lattitude has to be in the range of -90 to 90 degrees"); + return ResponseEntity.status(400).body("Lattitude has to be between -90 and 90 Degree"); } } catch (NumberFormatException e) { - throw new NumberFormatException("Lattitude has to be a decimal number"); + return ResponseEntity.status(400).body("Latitude has to be a decimal"); } try { longi = Double.valueOf(longitude); if (longi < -180 || longi > 180) { - throw new IllegalParameterException("Longitude has to be in the range of -180 to 180 degrees"); + return ResponseEntity.status(400).body("Longitude has to be in the range of -180 to 180 degrees"); } } catch (NumberFormatException e) { - throw new NumberFormatException("Longitude has to be a decimal number"); + return ResponseEntity.status(400).body("Longitude has to be a decimal number"); } Station station = new Station(); @@ -185,23 +189,24 @@ public class Controller { stationRepository.save(station); - return new Gson().toJson(station); - + return ResponseEntity.status(201).body(new Gson().toJson(station)); } + @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/checkAdmin") @ResponseBody - boolean checkAdmin(@RequestParam String token) { + ResponseEntity checkAdmin(@RequestParam String token) { User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); for (Role role : user.getRoles()) { if (role.getId() == 0) { // is admin - return true; + return ResponseEntity.status(200).body("User is Admin"); } } - return false; + return ResponseEntity.status(401).body("User is no Admin"); } + //Bis hier @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getAllStations") @ResponseBody From 91b0ca27c64de2dc0d7d326e6f73813a50fecd66 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Thu, 4 Apr 2019 22:49:56 +0200 Subject: [PATCH 07/16] auth store, new views, router changes added vuex store to make user details globally available. some changes in Login, Overview. added Cache & CacheView. added StationView & StationEdit. --- frontend/src/pages/Cache.vue | 21 ++ frontend/src/pages/CacheView.vue | 199 ------------------ frontend/src/pages/Login.vue | 51 ++--- frontend/src/pages/Overview.vue | 27 +-- .../pages/{Station.vue => StationEdit.vue} | 0 frontend/src/pages/StationView.vue | 65 ++++++ frontend/src/pages/TestCaches.vue | 84 -------- frontend/src/router/routes.js | 13 +- frontend/src/store/auth/mutations.js | 44 ++-- frontend/src/store/auth/state.js | 13 +- frontend/src/store/index.js | 4 +- 11 files changed, 145 insertions(+), 376 deletions(-) create mode 100644 frontend/src/pages/Cache.vue delete mode 100644 frontend/src/pages/CacheView.vue rename frontend/src/pages/{Station.vue => StationEdit.vue} (100%) create mode 100644 frontend/src/pages/StationView.vue delete mode 100644 frontend/src/pages/TestCaches.vue diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue new file mode 100644 index 0000000..896ba01 --- /dev/null +++ b/frontend/src/pages/Cache.vue @@ -0,0 +1,21 @@ + + + + + diff --git a/frontend/src/pages/CacheView.vue b/frontend/src/pages/CacheView.vue deleted file mode 100644 index 6257998..0000000 --- a/frontend/src/pages/CacheView.vue +++ /dev/null @@ -1,199 +0,0 @@ - - - diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index c5d83e3..cb0e8cc 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -21,8 +21,8 @@
{ - // this.$router.push('/') - // }) const data = { username: this.user.username, password: this.user.password - } //JSON.stringify(this.user); + }; + console.log("GET http://localhost:8080/api/login/ - json: " + JSON.stringify(data)); - this.$axios.post('http://localhost:8080/api/login', data) // TODO muss GET mit AUTH Header werden + + this.$axios.post('http://localhost:8080/api/login', data) .then((response) => { + // TODO Catch clause funktioniert nicht mehr wenn Statuscode zurückgegeben wird. -> hier if/else mit HTTP-Codes console.log("GET/POST http://localhost:8080/api/login/ - response: " + response.data); - //this.user.token = response.data; localStorage.setItem('userToken', JSON.stringify(response.data)); - //localStorage.setItem('userToken', response.data); - this.isAuthenticated(); + this.evalAuthentication(); }) .catch((error) => { console.log("error: " + error); this.credentialsDialog=true; }) }, - isAuthenticated: function () { - console.log("isAuthenticated()"); - console.log("content of localstorage: "); - console.log(JSON.parse(localStorage.getItem('userToken'))); - if (localStorage.getItem('userToken')) { - this.user.isAuthenticated = true; - } else { - this.user.isAuthenticated = false; - } + evalAuthentication: function () { + this.$store.commit('auth/SET_AUTHENTICATED'); }, logout: function () { console.log("logout()"); @@ -129,7 +124,7 @@ .then((response) => { console.log("GET/POST http://localhost:8080/api/logout/ - response: " + response.data); localStorage.removeItem('userToken'); - this.isAuthenticated(); + this.evalAuthentication(); }) .catch((error) => { }); diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index f9285c7..d206e53 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -32,9 +32,7 @@ :label="cache.name" :caption="cache.rankingPoints+' Punkte / Size '+cache.stationen.length" > - + @@ -45,8 +43,10 @@ - - + + + + @@ -90,21 +90,11 @@ } }, mounted: function () { - //this.header.h = style(this.$refs.layout.$refs.header, 'height') - // this.hheight = height(document.getElementById('qheader')); - // this.fheight = height(document.getElementById('qfooter')); }, computed: { - // mapHeight() { - // let header = this.hheight - // let footer = this.fheight - // let offset = header + footer + 1; - // console.log(offset) - // return {minHeight: offset ? `calc(100vh - ${offset}px)` : '100vh'}; - // }, - // computedMainStyle() { - // return { height: `calc( 100vh - ${this.header.h} )` }; - // } + hasAdminState() { + return this.$store.state.auth.userAuthenticated.isAdmin + } }, created: function() { console.log("created(): " + this.caches); @@ -129,6 +119,7 @@ this.$axios.get('http://localhost:8080/api/startCache', { params }) .then((response) => { console.log("Angefangen: " + response.data); + this.$router.push({ path: `/station/${cacheID}` }) }) } } diff --git a/frontend/src/pages/Station.vue b/frontend/src/pages/StationEdit.vue similarity index 100% rename from frontend/src/pages/Station.vue rename to frontend/src/pages/StationEdit.vue diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue new file mode 100644 index 0000000..f81a729 --- /dev/null +++ b/frontend/src/pages/StationView.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/frontend/src/pages/TestCaches.vue b/frontend/src/pages/TestCaches.vue deleted file mode 100644 index 59402e7..0000000 --- a/frontend/src/pages/TestCaches.vue +++ /dev/null @@ -1,84 +0,0 @@ - - - - - diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js index c027592..ce6b632 100644 --- a/frontend/src/router/routes.js +++ b/frontend/src/router/routes.js @@ -10,24 +10,19 @@ const routes = [ children: [{ path: "", component: () => import("pages/Overview.vue") }] }, { - path: "/testcaches/", + path: "/cache/", component: () => import("layouts/MyLayout.vue"), - children: [{path: "", component: () => import("pages/TestCaches.vue")}] - }, - { - path: "/cacheview/", - component: () => import("layouts/MyLayout.vue"), - children: [{ path: "", component: () => import("pages/CacheView.vue") }] + children: [{ path: "", component: () => import("pages/Cache.vue") }] }, { path: "/station/", component: () => import("layouts/MyLayout.vue"), - children: [{ path: "", component: () => import("pages/Station.vue") }] + children: [{ path: "", component: () => import("pages/StationEdit.vue") }] }, { path: "/station/:id", component: () => import("layouts/MyLayout.vue"), - children: [{ path: "", component: () => import("pages/Station.vue") }] + children: [{ path: "", component: () => import("pages/StationView.vue") }] }, { path: "/login/", diff --git a/frontend/src/store/auth/mutations.js b/frontend/src/store/auth/mutations.js index ffa7222..46266c0 100644 --- a/frontend/src/store/auth/mutations.js +++ b/frontend/src/store/auth/mutations.js @@ -1,38 +1,18 @@ import axios from 'axios' -/* -export function someMutation (state) { -} -*/ -export const evalAuth = (state) => { - console.log("isAuthenticated()"); - console.log(localStorage.getItem('userToken')); - if (localStorage.getItem('userToken')) { // TODO hier muss Abfrage mit API, z.B. /api/user?token="ME" stattfinden. - state.user.isAuthenticated = true; +export const SET_AUTHENTICATED = (state) => { + console.log("SET_AUTHENTICATED()"); + console.log(JSON.parse(localStorage.getItem('userToken'))); + if (localStorage.getItem('userToken')) { + state.userAuthenticated.isAuthenticated = true; } else { - state.user.isAuthenticated = false; + state.userAuthenticated.isAuthenticated = false; } }; -export const logout = (state) => { - console.log("logout()"); - console.log(localStorage.getItem('userToken')); - localStorage.removeItem('userToken'); - console.log(localStorage.getItem('userToken')); - state.commit(evalAuth(state)); +export const SET_USER_PROPERTIES = (state, user) => { + console.log("SET_USER_PROPERTIES()"); + console.log("still todo!"); }; -export const login = (state) => { - const data = { - username: state.user.username, - password: state.user.password - }; - console.log("GET http://localhost:8080/api/login/ - json: " + JSON.stringify(data)); - this.state.$axios.post('http://localhost:8080/api/login', data) // TODO muss GET mit AUTH Header werden - .then((response) => { - console.log("GET/POST http://localhost:8080/api/login/ - response: " + response.data); - localStorage.setItem('userToken', JSON.stringify(response)); - state.commit(evalAuth(state)); - }) - .catch((error) => { - console.log("error: " + error); - //errorDialog = true; - }) +export const SET_LOGOUT = (state) => { + console.log("SET_LOGOUT()"); + state.userAuthenticated = null; }; diff --git a/frontend/src/store/auth/state.js b/frontend/src/store/auth/state.js index 307952d..0e9581a 100644 --- a/frontend/src/store/auth/state.js +++ b/frontend/src/store/auth/state.js @@ -1,7 +1,12 @@ export default { - user: { - username: "moximoti", - password: "1234", - isAuthenticated: false + userAuthenticated: { + id: 1, + firstname: "t", + lastname: "v", + username: "mo", + email: "test@user.com", + rankingPointsSum: 345, + isAuthenticated: false, + isAdmin: false, }, } diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index dfbcdb1..8ccfe4c 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -45,8 +45,8 @@ export default function (/* { ssrContext } */) { */ if (process.env.DEV && module.hot) { module.hot.accept(['./auth'], () => { - const newShowcase = require('./auth').default; - store.hotUpdate({ modules: { showcase: newShowcase } }) + const auth = require('./auth').default; + store.hotUpdate({ modules: { auth: newAuth } }) }) } From 67a2defe413017bdb14a621d859358333ef1abe8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 5 Apr 2019 06:13:01 +0200 Subject: [PATCH 08/16] made all api methods public --- .../bugageocaching/controller/Controller.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 8992e4a..a2e93df 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -130,7 +130,7 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/logout") @ResponseBody - ResponseEntity logout(@RequestParam String token) { + public ResponseEntity logout(@RequestParam String token) { // System.out.println("logout"); User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); // System.out.println(token); @@ -146,10 +146,10 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/createStation") @ResponseBody - ResponseEntity createStation(@RequestParam String description, + public ResponseEntity createStation(@RequestParam String description, @RequestParam String lattitude, @RequestParam String longitude, - @RequestParam String solution) throws IllegalParameterException { + @RequestParam String solution) { if (description.length() == 0 || lattitude.length() == 0 || longitude.length() == 0 || solution.length() == 0) { return ResponseEntity.status(400).body("At least one Argument was empty"); @@ -196,7 +196,7 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/checkAdmin") @ResponseBody - ResponseEntity checkAdmin(@RequestParam String token) { + public ResponseEntity checkAdmin(@RequestParam String token) { User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); for (Role role : user.getRoles()) { if (role.getId() == 0) { // is admin @@ -210,18 +210,18 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getAllStations") @ResponseBody - ResponseEntity getAllStations() { + public ResponseEntity getAllStations() { return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll())); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/createCache") @ResponseBody - ResponseEntity createCache(@RequestParam String description, + public ResponseEntity createCache(@RequestParam String description, @RequestParam String name, @RequestParam String rankingPoints, @RequestParam(value = "rewardID", defaultValue = "-1") String rewardID, - @RequestParam List stationen) throws IllegalParameterException { + @RequestParam List stationen) { if (description.length() == 0 || name.length() == 0 || rankingPoints.length() == 0 || stationen.size() == 0) { return ResponseEntity.status(400).body("Fields can´t be empty"); @@ -271,7 +271,7 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/deleteCache") @ResponseBody - ResponseEntity deleteCache(@RequestParam String cacheID) { + public ResponseEntity deleteCache(@RequestParam String cacheID) { Optional optionalCache = cacheRepository.findById(Integer.valueOf(cacheID)); if (!optionalCache.isPresent()) { return ResponseEntity.status(404).body(new Gson().toJson("There is no cache with the ID " + cacheID)); @@ -299,7 +299,7 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getMyCaches") @ResponseBody - ResponseEntity getMyCaches(@RequestParam String token) { + public ResponseEntity getMyCaches(@RequestParam String token) { try { User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); if (user != null) { @@ -322,14 +322,14 @@ public class Controller { @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getRankingList") @ResponseBody - ResponseEntity getRankingList() { + public ResponseEntity getRankingList() { return ResponseEntity.status(200).body(new Gson().toJson(userRepository.getRankingList())); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getUser") @ResponseBody - ResponseEntity getUser(@RequestParam String token) { + public ResponseEntity getUser(@RequestParam String token) { try { User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); if (user != null) { From 01d860542b453d3c408629ddbef968513527e4a7 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Fri, 5 Apr 2019 11:04:53 +0200 Subject: [PATCH 09/16] Changed some ResponseEntities --- .../bugageocaching/controller/Controller.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index a2e93df..a962339 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -109,8 +109,8 @@ public class Controller { CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get(); bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); } else { - throw new IllegalParameterException("There is no cacheAccesDefinition with the ID " + 0); - } + return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0); + } bearbeitetRepository.save(bearbeitet); @@ -147,11 +147,11 @@ public class Controller { @RequestMapping("/api/createStation") @ResponseBody public ResponseEntity createStation(@RequestParam String description, - @RequestParam String lattitude, + @RequestParam String latitude, @RequestParam String longitude, @RequestParam String solution) { - if (description.length() == 0 || lattitude.length() == 0 || longitude.length() == 0 || solution.length() == 0) { + if (description.length() == 0 || latitude.length() == 0 || longitude.length() == 0 || solution.length() == 0) { return ResponseEntity.status(400).body("At least one Argument was empty"); } @@ -159,9 +159,9 @@ public class Controller { double longi; try { - latti = Double.valueOf(lattitude); + latti = Double.valueOf(latitude); if (latti < -90 || latti > 90) { - return ResponseEntity.status(400).body("Lattitude has to be between -90 and 90 Degree"); + return ResponseEntity.status(400).body("Latitude has to be between -90 and 90 Degree"); } } catch (NumberFormatException e) { return ResponseEntity.status(400).body("Latitude has to be a decimal"); @@ -198,6 +198,9 @@ public class Controller { @ResponseBody public ResponseEntity checkAdmin(@RequestParam String token) { User user = userRepository.findByUsername(token.substring(0, token.indexOf("$"))); + if(user == null){ + return ResponseEntity.status(404).body("User was not found"); + } for (Role role : user.getRoles()) { if (role.getId() == 0) { // is admin return ResponseEntity.status(200).body("User is Admin"); From 239dc92b5801f7f5539275bef0788a2bac8840fe Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Fri, 5 Apr 2019 14:40:10 +0200 Subject: [PATCH 10/16] changes in Cache & Station Editpages, added cacheCollector Store --- frontend/quasar.conf.js | 2 + frontend/src/pages/Cache.vue | 77 ++++++++++++++++--- frontend/src/pages/Overview.vue | 4 +- frontend/src/pages/StationEdit.vue | 57 +++++++++++--- frontend/src/store/cacheCollector/actions.js | 4 + frontend/src/store/cacheCollector/getters.js | 4 + frontend/src/store/cacheCollector/index.js | 12 +++ .../src/store/cacheCollector/mutations.js | 4 + frontend/src/store/cacheCollector/state.js | 3 + frontend/src/store/index.js | 22 ++---- 10 files changed, 152 insertions(+), 37 deletions(-) create mode 100644 frontend/src/store/cacheCollector/actions.js create mode 100644 frontend/src/store/cacheCollector/getters.js create mode 100644 frontend/src/store/cacheCollector/index.js create mode 100644 frontend/src/store/cacheCollector/mutations.js create mode 100644 frontend/src/store/cacheCollector/state.js diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index 42861b5..b557976 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -64,6 +64,8 @@ module.exports = function (ctx) { 'QExpansionItem', 'QParallax', 'QEditor', + 'QSelect', + 'QField', ], directives: [ diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index 896ba01..513310e 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -1,19 +1,76 @@