From 71b0618ab293bdd74f4a2b00e1708739506b07c2 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Wed, 17 Apr 2019 23:22:44 +0200 Subject: [PATCH] Fixed login, several other fixes --- frontend/quasar.conf.js | 2 +- frontend/src/layouts/MyLayout.vue | 8 +++- frontend/src/pages/Cache.vue | 2 +- frontend/src/pages/Login.vue | 44 ++++++++++++++----- frontend/src/pages/Overview.vue | 2 +- frontend/src/pages/Profile.vue | 2 +- frontend/src/pages/StationView.vue | 8 ++-- frontend/src/pages/ranking.vue | 2 +- frontend/src/store/auth/mutations.js | 10 +++-- .../src/store/cacheCollector/mutations.js | 2 +- frontend/src/store/dialog/mutations.js | 1 + 11 files changed, 56 insertions(+), 27 deletions(-) diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index 1dc0d44..b175999 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -107,8 +107,8 @@ module.exports = function (ctx) { API: JSON.stringify('http://localhost:8080') } : { // Base URL for API-Calls: PRODUCTION (build) - API: JSON.stringify('http://se.hs-heilbronn.de:8090') //API: JSON.stringify('http://se.hs-heilbronn.de:8090') + API: JSON.stringify('http://localhost:8080') } }, diff --git a/frontend/src/layouts/MyLayout.vue b/frontend/src/layouts/MyLayout.vue index 6b82285..6bc4eb9 100644 --- a/frontend/src/layouts/MyLayout.vue +++ b/frontend/src/layouts/MyLayout.vue @@ -109,7 +109,7 @@ -
Fehler
+
{{ dialogTitle }}
@@ -160,6 +160,12 @@ return this.$store.state.dialog.dialog.message; }, }, + dialogTitle: { + get() { + console.log("get dialogTitle: "+this.$store.state.dialog.dialog.title) + return this.$store.state.dialog.dialog.title; + }, + }, dialogColorBg: { get() { console.log("get dialogColorBg: " + this.$store.state.dialog.dialog.colorBackground) diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index 27bcf24..b89af32 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -154,7 +154,7 @@ if (this.isNewCache) { console.log(this.cache); console.log(JSON.stringify(this.cache)); - this.$axios.post('http://localhost:8080/api/createCache', this.cache) + this.$axios.post('/api/createCache', this.cache) .then((response) => { console.log("POST api/createCache: " + response.statusText); this.$store.commit('cacheCollector/RESET_NEW_CACHE'); diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index e6fc7fd..649de1c 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -6,7 +6,7 @@
-
@@ -69,8 +69,8 @@ data() { return { user: { - username: "moximoti", - password: "1234", + email: "volkmann@geocaching.de", + password: "0123456789", //token: "", // evalAuthentication: false }, @@ -99,22 +99,42 @@ login: function () { const data = { - username: this.user.username, + email: this.user.email, password: this.user.password }; - console.log("GET http://localhost:8080/api/login/ - json: " + JSON.stringify(data)); + console.log("GET /api/login/ - json: " + JSON.stringify(data)); - this.$axios.post('http://localhost:8080/api/login', data) + this.$axios.post('http://www.se.hs-heilbronn.de:8090/buga19usermanagement/account/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); + console.log("GET/POST /api/login/ - response: "); + console.log(response.data); + console.log("TOKEN"); + console.log(response.data.token); localStorage.setItem('userToken', JSON.stringify(response.data)); this.evalAuthentication(); }) .catch((error) => { - console.log("error: " + error); - this.credentialsDialog = true; + let message; + let header = "Fehler: "; + if (error.response) { + console.log("ERROR RESPONSE") + // The request was made and the server responded with a status code + // that falls out of the range of 2xx + message = error.response.data.error; + header += error.response.status; + } else if (error.request) { + // The request was made but no response was received + // `error.request` is an instance of XMLHttpRequest in the browser and an instance of + // http.ClientRequest in node.js + message = error.request; + } else { + // Something happened in setting up the request that triggered an Error + console.log('Error', error.message); + message = error.message; + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, }); }) }, evalAuthentication: function () { @@ -124,13 +144,13 @@ logout: function () { console.log("logout()"); console.log(JSON.parse(localStorage.getItem('userToken'))); - // this.$axios.get('http://localhost:8080/api/logout', { + // this.$axios.get('/api/logout', { // params: { // token: JSON.parse(localStorage.getItem('userToken')) // } // }) // .then((response) => { - // console.log("GET/POST http://localhost:8080/api/logout/ - response: " + response.data); + // console.log("GET/POST /api/logout/ - response: " + response.data); // }) // .catch((error) => { // }); diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 0831ffa..b0e123f 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -139,7 +139,7 @@ } console.log(params); - this.$axios.get('http://localhost:8080/api/startCache', {params}) + this.$axios.get('/api/startCache', {params}) .then((response) => { console.log(response.data); // TODO wenn cache angefangen, dann suche die letzte gefundene Station diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index 8a48bea..9b13749 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -124,7 +124,7 @@ methods: { fetchUserCaches: function() { const token = JSON.parse(localStorage.getItem('userToken')); - this.$axios.get('http://localhost:8080/api/getMyCaches', { params: {token}} ) + this.$axios.get('/api/getMyCaches', { params: {token}} ) .then((response) => { this.startedCaches = response.data; }); diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index f748a90..8b13337 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -67,9 +67,9 @@ }, methods: { fetchData() { - this.$axios.get('http://localhost:8080/api/allCaches') + this.$axios.get('/api/allCaches') .then((response) => { - console.log("http://localhost:8080/api/allCaches"); + console.log("/api/allCaches"); console.log(JSON.stringify(this.data)); console.log(this.data); console.log(response.data); @@ -78,9 +78,9 @@ this.data.cacheName = cache.name; this.cache = cache; console.log(JSON.stringify(this.data)); - this.$axios.get('http://localhost:8080/api/getAllStations') + this.$axios.get('/api/getAllStations') .then((response) => { - console.log("http://localhost:8080/api/getAllStations"); + console.log("/api/getAllStations"); console.log(response.data); const stationView = response.data.find(station => station.id === Number(this.$route.params.id)); console.log(JSON.stringify(stationView)); diff --git a/frontend/src/pages/ranking.vue b/frontend/src/pages/ranking.vue index 85ae744..6ec447d 100644 --- a/frontend/src/pages/ranking.vue +++ b/frontend/src/pages/ranking.vue @@ -77,7 +77,7 @@ }, methods: { fetchRankinglist() { - this.$axios.get('http://localhost:8080/api/getRankingList') + this.$axios.get('/api/getRankingList') .then((response) => { console.log("Rankinglist: "); console.log(response.data); diff --git a/frontend/src/store/auth/mutations.js b/frontend/src/store/auth/mutations.js index fed76c1..e096bee 100644 --- a/frontend/src/store/auth/mutations.js +++ b/frontend/src/store/auth/mutations.js @@ -1,4 +1,5 @@ -import axios from 'axios' +import { axiosInstance } from '../../boot/axios' + export const SET_AUTHENTICATED = (state) => { console.log("SET_AUTHENTICATED()"); console.log(JSON.parse(localStorage.getItem('userToken'))); @@ -17,14 +18,15 @@ export const SET_LOGOUT = (state) => { }; export const SET_USER = (state) => { console.log("SET_USER()"); + console.log(process.env.API) if (localStorage.getItem('userToken')) { - axios.get('http://localhost:8080/api/getUser', { + axiosInstance.get('/api/getUser', { params: { - token: JSON.parse(localStorage.getItem('userToken')) + token: JSON.parse(localStorage.getItem('userToken')).token } }) .then((response) => { - console.log("GET/POST http://localhost:8080/api/getUser - response: "); + console.log("GET/POST /api/getUser - response: "); console.log(response.data); state.userAuthenticated = response.data; state.isAuthenticated = true; diff --git a/frontend/src/store/cacheCollector/mutations.js b/frontend/src/store/cacheCollector/mutations.js index 646ab0f..383330d 100644 --- a/frontend/src/store/cacheCollector/mutations.js +++ b/frontend/src/store/cacheCollector/mutations.js @@ -33,7 +33,7 @@ export const RESET_NEW_CACHE = (state) => { }; export const LOAD_REMOTE_CACHE = (state, id) => { console.log("LOAD_REMOTE_CACHE: get caches from remote"); - this.$axios.get('http://localhost:8080/api/allCaches') + this.$axios.get('/api/allCaches') .then((response) => { const allCaches = JSON.parse(response.data); console.log("Caches: " + allCaches.length); diff --git a/frontend/src/store/dialog/mutations.js b/frontend/src/store/dialog/mutations.js index cb09e12..8994399 100644 --- a/frontend/src/store/dialog/mutations.js +++ b/frontend/src/store/dialog/mutations.js @@ -1,6 +1,7 @@ export function NEW_MESSAGE_DIALOG (state, messageObject) { console.log("NEW_MESSAGE_DIALOG"); + console.log(messageObject); if (messageObject == null) { state.dialog.show = true; return;