Fixed login, several other fixes

This commit is contained in:
Timo Volkmann 2019-04-17 23:22:44 +02:00
parent 3110f40826
commit 71b0618ab2
11 changed files with 56 additions and 27 deletions

View File

@ -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')
}
},

View File

@ -109,7 +109,7 @@
<q-dialog v-model="dialogShow" persistent transition-show="scale" transition-hide="scale">
<q-card :class="dialogColorBg" style="min-width: 300px">
<q-card-section>
<div class="text-h6">Fehler</div>
<div class="text-h6">{{ dialogTitle }}</div>
</q-card-section>
<q-card-section>
@ -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)

View File

@ -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');

View File

@ -6,7 +6,7 @@
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-input outlined filled stack-label v-model="user.username" type="text" label="Benutzername"
<q-input outlined filled stack-label v-model="user.email" type="text" label="Benutzername"
autocomplete="username"/>
</div>
</div>
@ -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) => {
// });

View File

@ -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

View File

@ -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;
});

View File

@ -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));

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;