diff --git a/build.gradle b/build.gradle index e2a06be..733231a 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ dependencies { runtimeOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'mysql:mysql-connector-java' testImplementation 'org.springframework.boot:spring-boot-starter-test' + compile 'org.springframework.boot:spring-boot-starter-web' //JPA compile 'org.springframework.boot:spring-boot-starter-data-jpa' @@ -40,7 +41,7 @@ dependencies { compile 'org.springframework.boot:spring-boot-starter-tomcat' //compile 'org.springframework.boot:spring-boot-starter-security' - compile 'org.springframework.boot:spring-boot-starter-actuator' + //compile 'org.springframework.boot:spring-boot-starter-actuator' //compile 'org.springframework.boot:spring-boot-starter-aop' //ompile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.2.0.RELEASE' diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index 5fc390f..3765fb7 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -101,7 +101,7 @@ module.exports = function (ctx) { // extractCSS: false, //distDir: 'springwebdir/{ctx.modeName}', distDir: '../src/main/resources/public/', - extendWebpack (cfg) { + extendWebpack(cfg) { cfg.module.rules.push({ enforce: 'pre', test: /\.(js|vue)$/, @@ -112,12 +112,12 @@ module.exports = function (ctx) { env: ctx.dev ? { // Base URL for API-Calls: DEV API: JSON.stringify('http://localhost:8080'), - // API: JSON.stringify('https://seserver.se.hs-heilbronn.de:8443/buga19geocaching'), + //API: JSON.stringify('https://seserver.se.hs-heilbronn.de:9443/buga19geocaching'), USER_API: JSON.stringify('https://seserver.se.hs-heilbronn.de:9443/buga19usermanagement') } : { // Base URL for API-Calls: PRODUCTION (build) - API: JSON.stringify('http://localhost:8080'), - //API: JSON.stringify('https://seserver.se.hs-heilbronn.de:8443/buga19geocaching'), + //API: JSON.stringify('http://localhost:8080'), + API: JSON.stringify('https://seserver.se.hs-heilbronn.de:9443/buga19geocaching'), USER_API: JSON.stringify('https://seserver.se.hs-heilbronn.de:9443/buga19usermanagement') } }, @@ -183,7 +183,7 @@ module.exports = function (ctx) { electron: { // bundler: 'builder', // or 'packager' - extendWebpack (cfg) { + extendWebpack(cfg) { // do something with Electron main process Webpack cfg // chainWebpack also available besides this extendWebpack }, diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index 3b3cb3f..c711f26 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -35,7 +35,8 @@
- + @@ -50,46 +51,101 @@ - + - Neues Team erstellen + Neues Team erstellen + Neues Team erstellen
(Team verlassen um Option zu + nutzen) +
-

Teammitglieder

- -
-

Einladungen

- -
- +
+

Teammitglieder

+ +
+

Einladungen

+ +
+ +
+
+

Teamstatus

+

{{currentTeamStatus}}

+ +
+ +
+
+ +
+ +
-
-

Teamstatus

-

{{currentTeamStatus}}

- -
- +
+ + + + + + + + + + +
+
+ +
@@ -119,15 +175,23 @@ data() { return { tab: 'profile', - startedCaches: [], inviteMail: "", - currentTeamStatus: "Dienstag 15:00 Treffen zum Blumencache", + currentTeamStatus: "", teamStatus: "", + userName: "", email: null, userRanking: null, teamName: null, + boolAlreadyInTeam: false, teamRanking: null, dropDownSelectedItem: null, + boolMyTeam: true, + boolInvites: false, + boolCreateTeam: false, + newTeamName: "", + leaveTeamCheck: "", + teamMembers: [], + teamInvites: [], columns: [ { name: 'desc', @@ -144,6 +208,10 @@ } ], data: [ + { + name: 'Benutzername', + userData: this.userName, + }, { name: 'E-Mail', userData: this.email, @@ -170,43 +238,25 @@ field: row => row.name, format: val => `${val}`, }, + { + name: 'email', + label: 'Email', + required: true, + align: 'left', + field: 'email', + }, { name: 'ranking', - label: 'Solo-Ranglistenpunkte', + label: 'Rangliste (Solo)', required: true, align: 'left', field: 'ranking', sortable: true, } ], - teamData: [ - { - name: 'BuGaCacher2019', - ranking: 10, - }, - { - name: 'Max', - ranking: 5, - }, - { - name: 'Timo', - ranking: 4, - }, - { - name: 'Katharina', - ranking: 3, - }, - { - name: 'Michael', - ranking: 2, - }, - { - name: 'Robin', - ranking: 1, - }, - ], + teamData: [], pagination: { - sortBy: 'name', + sortBy: 'ranking', descending: false, page: 1, rowsPerPage: 10 @@ -220,19 +270,41 @@ hasAdminState() { return this.$store.getters['auth/GET_ADMINSTATE']; }, + newTeamNameValidationSuccesful() { + if (this.newTeamName.length >= 5) { + return true; + } + return false; + }, + teamInviteChecked() { + if (this.validateEmail(this.inviteMail)) { + return true; + } + return false; + }, + teamStatusChecked() { + if (this.teamStatus.length <= 160) { + return true; + } + return false; + }, + leaveConfirmed() { + if (this.leaveTeamCheck === 'BESTÄTIGEN'){ + return true; + } + return false; + } }, created: function () { this.$store.commit('auth/SET_AUTHENTICATED'); this.$store.commit('auth/SET_USER'); + this.userName = JSON.parse(localStorage.getItem('userToken')).name; + this.data[0].userData = this.userName; this.email = JSON.parse(localStorage.getItem('userMail')); - this.data[0].userData = this.email; - this.userRanking = "1234"; - this.data[1].userData = this.userRanking; - this.teamName = "BuGa19Community"; - this.data[2].userData = this.teamName; - this.dropDownSelectedItem = this.teamName; - this.teamRanking = "2019"; - this.data[3].userData = this.teamRanking; + this.data[1].userData = this.email; + this.getPersonalRanking(); + this.getTeamData(); + this.fetchTeamInvites(); }, methods: { validateEmail(email) { @@ -240,72 +312,243 @@ return re.test(String(email).toLowerCase()); }, getPersonalRanking() { - const name = JSON.parse(localStorage.getItem('userToken')).name; - console.log(JSON.parse(localStorage.getItem('userToken')).name); - this.$axios.get('/api/hello', {params: {name}}) + let email = this.email; + this.$axios.get('/api/getRankingPlace', {params: {email}}) .then((response) => { this.userRanking = response.data; - console.log(response.data); + this.data[2].userData = this.userRanking; }).catch((error) => { - // Error - let msg; - let title; - if (error.response) { - // The request was made and the server responded with a status code - title = "Problem with response!"; - msg = error.response; - } else if (error.request) { - // The request was made but no response was received - title = "Problem with request!"; - msg = "Error occured due to wrong server request!" - console.log(error.request); - } else { - // Something happened in setting up the request that triggered an Error - title = "Error"; - msg = error.message; - console.log('Error', error.message); - } - console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,}); + this.handleError(error); }) }, getTeamData() { - const userName = {name: JSON.parse(localStorage.getItem('userToken')).name}; - this.$axios.get('/api/getTeam', {params: userName}) + let token; + if (localStorage.getItem('userToken')) { + token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + this.$axios.get('/api/getTeamOfUser', {params: {token}}) .then(response => { + if (response.data === '') { + this.boolAlreadyInTeam = false; + this.teamName = "Aktuell in keinem Team"; + this.currentTeamStatus = ""; + this.teamRanking = "-"; + this.dropDownSelectItem('Offene Teameinladungen'); + } else { + this.boolAlreadyInTeam = true; + this.teamName = response.data.name; + this.currentTeamStatus = response.data.teamStatus; + //this.teamRanking = response.data.teamRanking; + this.fetchTeamMembers(); + } + this.data[3].userData = this.teamName; + this.dropDownSelectedItem = this.teamName; + this.data[4].userData = this.teamRanking; console.log("getTeam: " + response); }).catch((error) => { - // Error - let msg; - let title; - if (error.response) { - // The request was made and the server responded with a status code - title = "Problem with response!"; - msg = error.response; - } else if (error.request) { - // The request was made but no response was received - title = "Problem with request!"; - msg = "Error occured due to wrong server request!" - console.log(error.request); - } else { - // Something happened in setting up the request that triggered an Error - title = "Error"; - msg = error.message; - console.log('Error', error.message); - } - console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,}); + this.handleError(error); }) - }, dropDownSelectItem(item) { if (item === 'team') { this.dropDownSelectedItem = this.teamName; + this.boolMyTeam = true; + this.boolInvites = false; + this.boolCreateTeam = false; + } else if (item === 'Offene Teameinladungen') { + this.dropDownSelectedItem = item; + this.boolMyTeam = false; + this.boolInvites = true; + this.boolCreateTeam = false; } else { this.dropDownSelectedItem = item; + this.boolMyTeam = false; + this.boolInvites = false; + this.boolCreateTeam = true; } }, + createTeam() { + let params = {}; + if (localStorage.getItem('userToken')) { + params.token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + params.name = this.newTeamName; + this.$axios.post('/api/createTeam', null, {params}) + .then((response) => { + console.log("createTeam: " + response); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { + message: "Das Team " + this.newTeamName + " wurde erfolgreich erstellt!", + title: "Teamerstellung", + color: "blue" + }); + }).catch((error) => { + this.handleError(error); + }) + }, + leaveTeam() { + let params = {}; + if (localStorage.getItem('userToken')) { + params.token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + this.$axios.put('/api/leaveTeam', null, {params}) + .then((response) => { + console.log("createTeam: " + response); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { + message: "Dus hast das Team " + this.teamName + " verlassen!", + title: "Team verlassen", + color: "blue" + }); + this.getTeamData(); + }).catch((error) => { + this.handleError(error); + }) + }, + fetchTeamMembers() { + let name = this.teamName; + this.$axios.get('/api/getTeamMembers', {params: {name}}) + .then((response) => { + console.log(response.data); + this.teamMembers = response.data; + for (var i = 0; i < this.teamMembers.length; i++) { + let member = {}; + member.name = this.teamMembers[i].username; + member.email = this.teamMembers[i].email; + this.getMemberRanking(member, member.email); + this.teamData.push(member); + } + }).catch((error) => { + this.handleError(error); + }) + }, + getMemberRanking(member, email) { + let ranking; + this.$axios.get('/api/getRankingPlace', {params: {email}}) + .then((response) => { + ranking = response.data; + member.ranking = ranking; + }).catch((error) => { + this.handleError(error); + }); + }, + fetchTeamInvites() { + let token; + if (localStorage.getItem('userToken')) { + token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + this.$axios.get('/api/getMyTeamInvites', {params: {token}}) + .then((response) => { + this.teamInvites = response.data; + console.log(this.teamInvites); + }).catch((error) => { + this.handleError(error); + }) + }, + joinTeam(teamInvite) { + let params = {}; + if (localStorage.getItem('userToken')) { + params.token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + params.teamID = teamInvite.team.id; + this.$axios.put('/api/joinTeam', null, {params}) + .then((response) => { + console.log(response.data); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { + message: "Du bist dem Team " + teamInvite.team.name + " erfolgreich beigetreten!", + title: "Teambeitrittsanfrage", + color: "blue" + }); + this.getTeamData(); + }).catch((error) => { + this.handleError(error); + }) + }, + deleteTeamInvite(teamInvite) { + let params = {}; + if (localStorage.getItem('userToken')) { + params.token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + params.teamInviteID = teamInvite.id; + this.$axios.delete('/api/deleteTeamInvite', {params}) + .then((response) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { + message: "Du hast die Anfrage von Team " + teamInvite.team.name + " gelöscht!", + title: "Teambeitrittsanfrage", + color: "blue" + }); + this.getTeamData(); + }).catch((error) => { + this.handleError(error); + }) + }, + sendTeamInvite() { + let params = {}; + if (localStorage.getItem('userToken')) { + params.token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + params.invitedUserEmail = this.inviteMail; + this.$axios.post('/api/sendTeamInvite', null, {params}) + .then((response) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { + message: "Du hast " + params.invitedUserEmail + " eingeladen!", + title: "Einladung ins Team", + color: "blue" + }); + }).catch((error) => { + this.handleError(error); + }) + }, + setTeamStatus() { + let params = {}; + if (localStorage.getItem('userToken')) { + params.token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } + params.teamStatus = this.teamStatus; + this.$axios.put('/api/setTeamStatus', null, {params}) + .then((response) => { + this.getTeamData(); + }).catch((error) => { + this.handleError(error); + }) + }, + handleError(error) { + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!"; + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,}); + } } } diff --git a/frontend/src/pages/Register.vue b/frontend/src/pages/Register.vue index 48b3b0c..ccd2b3f 100644 --- a/frontend/src/pages/Register.vue +++ b/frontend/src/pages/Register.vue @@ -3,6 +3,14 @@
+
+
+
+ +
+
+
@@ -63,6 +71,7 @@ data() { return { user: { + name: "", email: "", checkemail: "", password: "", @@ -72,7 +81,8 @@ }, computed: { validationSuccesful() { - if (this.validateEmail(this.user.email) + if (this.user.name.length >= 2 + && this.validateEmail(this.user.email) && this.user.email === this.user.checkemail && this.user.password.length >= 8 && this.user.password === this.user.checkpassword) { @@ -93,7 +103,7 @@ if (this.user.email === this.user.checkemail && this.user.password === this.user.checkpassword) { const data = { - name: this.user.email, + name: this.user.name, password: this.user.password, email: this.user.email, roles: [ @@ -111,7 +121,7 @@ 'Authorization': 'Bearer ' + token, } }) - .then((response) => { + .then((response) => { console.log(response.data); if (response.status === 201) { this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { @@ -121,20 +131,20 @@ }); this.autoLogin(); } - }) - .catch((error) => { + }) + .catch((error) => { let message; let header = "Unbekannter Fehler..."; if (error.response) { console.log(error.response) if (error.response.status === 409) { - message= "Die E-Mail-Adresse wird bereits verwendet!"; - header= "Anmeldedaten überprüfen!"; - } + message= "Die E-Mail-Adresse wird bereits verwendet!"; + header= "Anmeldedaten überprüfen!"; + } } else if (error.request) { - console.log(error.request); - header = "Anfrage fehlgeschlagen!"; - message = "Die Verbindung zum Server ist gestört. Versuchen Sie es später noch einmal."; + console.log(error.request); + header = "Anfrage fehlgeschlagen!"; + message = "Die Verbindung zum Server ist gestört. Versuchen Sie es später noch einmal."; } this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: message, title: header}); }); diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 9b6ae81..a9643d9 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -1,7 +1,6 @@ package hhn.labsw.bugageocaching.controller; import com.google.gson.Gson; -import com.mashape.unirest.http.exceptions.UnirestException; import hhn.labsw.bugageocaching.entities.*; import hhn.labsw.bugageocaching.helper.POI; import hhn.labsw.bugageocaching.helper.RankingListHelper; @@ -602,15 +601,17 @@ public class Controller { int i = 0; + // zählt teammitglieder - for (User_Info userInfo1 : user_infoRepository.findAll()) { + List user_infos = user_infoRepository.findByTeam(team); + /*for (User_Info userInfo1 : user_infoRepository.findAll()) { if (userInfo1.getTeam().equals(team)) { i++; } - } + }*/ // wenn maximalanzahl der teammitglieder erreicht... - if (i >= 10) { + if (user_infos.size() >= 10) { return ResponseEntity.status(400).body("The team already has 10 members"); } @@ -618,6 +619,8 @@ public class Controller { user_info.setTeam(team); user_infoRepository.save(user_info); + TeamInvite teamInvite = teamInviteRepository.findByUserAndTeam(user, team); + teamInviteRepository.delete(teamInvite); return ResponseEntity.status(200).body(new Gson().toJson(team)); } @@ -784,13 +787,20 @@ public class Controller { User user = (User) getUser.getBody(); - List teamInvitesList = new ArrayList<>(); + List teamInvitesList = teamInviteRepository.findByUser(user); - for (TeamInvite teamInvite : teamInviteRepository.findAll()) { + for (TeamInvite tmp : teamInvitesList){ + tmp.setUser(null); + } + + /*for (TeamInvite teamInvite : teamInviteRepository.findAll()) { if (teamInvite.getUser() == user) { teamInvitesList.add(teamInvite); } - } + }+/ + + + */ return ResponseEntity.status(200).body(new Gson().toJson(teamInvitesList)); } @@ -950,7 +960,7 @@ public class Controller { @ApiResponse(code = 401, message = "JWT Token expired"), @ApiResponse(code = 400, message = "Something went wrong at verification") }) - @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose + @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose @RequestMapping(value = "/api/getRankingPlace", method = RequestMethod.GET, produces = "application/json") public ResponseEntity getRankingPlace(@RequestParam String email) { return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(email)); @@ -1028,6 +1038,7 @@ public class Controller { @ApiResponse(code = 401, message = "JWT Token expired"), @ApiResponse(code = 400, message = "Something went wrong at verification") }) + @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping(value = "/api/getTeamOfUser", method = RequestMethod.GET, produces = "application/json") public ResponseEntity getTeamOfUser(@RequestParam String token) { diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/TeamInviteRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/TeamInviteRepository.java index 1454dfa..0031632 100644 --- a/src/main/java/hhn/labsw/bugageocaching/repositories/TeamInviteRepository.java +++ b/src/main/java/hhn/labsw/bugageocaching/repositories/TeamInviteRepository.java @@ -6,6 +6,9 @@ import hhn.labsw.bugageocaching.entities.TeamInvite; import hhn.labsw.bugageocaching.entities.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface TeamInviteRepository extends JpaRepository { TeamInvite findByUserAndTeam(User user, Team team); + List findByUser(User user); } diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/TeamRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/TeamRepository.java index 608ede6..bf00017 100644 --- a/src/main/java/hhn/labsw/bugageocaching/repositories/TeamRepository.java +++ b/src/main/java/hhn/labsw/bugageocaching/repositories/TeamRepository.java @@ -15,9 +15,9 @@ public interface TeamRepository extends JpaRepository { @Query(value = "SELECT *\n" + "FROM user\n" + "WHERE id IN (\n" + - " SELECT user_id\n" + - " FROM user_info\n" + - " WHERE team_id = (SELECT team_id FROM team WHERE name = ?1))", nativeQuery = true) + "SELECT user_id\n" + + "FROM user_info\n" + + "WHERE team_id = (SELECT team.id FROM team WHERE name = ?1));", nativeQuery = true) List getTeammembers(String name); diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/UserRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/UserRepository.java index af74433..8573416 100644 --- a/src/main/java/hhn/labsw/bugageocaching/repositories/UserRepository.java +++ b/src/main/java/hhn/labsw/bugageocaching/repositories/UserRepository.java @@ -9,7 +9,7 @@ import java.util.List; public interface UserRepository extends CrudRepository { User findByEmail(String email); - @Query(value = "SELECT DISTINCT u.id AS ID, SUBSTRING_INDEX(u.email, '@', 1) AS Name, ui.ranking_points_sum AS Ranglistenpunkte\n" + + @Query(value = "SELECT DISTINCT u.id AS ID, username AS Name, ui.ranking_points_sum AS Ranglistenpunkte\n" + "FROM user u,\n" + " user_info ui,\n" + " user_roles ur\n" + diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java index 309cc41..252547e 100644 --- a/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java +++ b/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java @@ -1,5 +1,6 @@ package hhn.labsw.bugageocaching.repositories; +import hhn.labsw.bugageocaching.entities.Team; import hhn.labsw.bugageocaching.entities.User; import hhn.labsw.bugageocaching.entities.User_Info; import org.springframework.data.jpa.repository.Query; @@ -10,4 +11,5 @@ import java.util.Optional; public interface User_InfoRepository extends CrudRepository { User_Info findUser_InfoByUser(User user); + List findByTeam(Team team); } diff --git a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java index 55cbf2c..c42e4d0 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java @@ -1,5 +1,6 @@ package hhn.labsw.bugageocaching.util; +import com.google.gson.Gson; import hhn.labsw.bugageocaching.entities.*; import hhn.labsw.bugageocaching.repositories.*; import io.jsonwebtoken.Claims; @@ -181,11 +182,12 @@ public class FinderUtil { list) { User tmp = new User(); tmp.setUsername((String) obj[3]); + tmp.setEmail((String) obj[1]); sendBack.add(tmp); } - return ResponseEntity.status(200).body(list); + return ResponseEntity.status(200).body(new Gson().toJson(sendBack)); } else { return ResponseEntity.status(404).body("Couldnt find Team member of Team " + name); }