diff --git a/backend/views.go b/backend/views.go index 3b1b7e9..4a49553 100644 --- a/backend/views.go +++ b/backend/views.go @@ -240,6 +240,7 @@ func updateLogoutUserView(c *gin.Context) { var logoutUser User //login zalogowane uzytkownika c.Bind(&logoutUser) _login := logoutUser.Login + fmt.Println("Wylogowano uzytkownika: %s", _login) err := updateLogoutUser(_login) if err != nil { c.JSON(http.StatusOK, "[updateLoggedUserView] Nie udalo sie zaktualizowac wylogowanego uzytkownika") diff --git a/frontend/app/src/components/Navbar.vue b/frontend/app/src/components/Navbar.vue index c60691a..97ada4a 100644 --- a/frontend/app/src/components/Navbar.vue +++ b/frontend/app/src/components/Navbar.vue @@ -55,9 +55,11 @@ - Wyloguj + Wyloguj + - Zaloguj + Zaloguj + exit_to_app @@ -102,7 +104,7 @@ export default { drawer: false, //niepokazywac na poczatku snackbar: false, snackbarLogout: false, - isLogged: true, + isLogged: null, snackbarLogin: false, snackbarLoginRequred: false, } @@ -114,22 +116,51 @@ export default { }, methods:{ userAction(){ - if(this.isLogged){ - this.snackbarLogout = true - this.isLogged = false - this.$store.dispatch('removeLoggedUser', localStorage.getItem('user')) + this.checkIsUserLogged() - console.log("wylogowano") - localStorage.setItem('token',null); - localStorage.setItem('user', null); - this.$router.push('/') + if(this.isLogged){// jesli jest zalogowany to wyloguj + console.log("Procedura wylogowania wylogowania") + this.snackbarLogout = true + + this.$store.dispatch('removeLoggedUser', localStorage.getItem('user')) + + localStorage.setItem('token',null); + localStorage.setItem('user', null); + this.isLogged = false + + + + // this.checkIsUserLogged() + + this.$router.push('/') //Czy sie zaloguje czy wyloguje to i tak do logowania ma wrócić } - else{ - this.snackbarLogout = false - this.snackbarLogin = true - this.isLogged = true - console.log("zalogowano") + else{ + // this.checkIsUserLogged() + this.$router.push('/') + + } + + + }, + checkIsUserLogged(){ + if (localStorage.getItem('token') === "null"){ //brak tokenu jest wylogowany + this.isLogged = false + console.log("NIEZALOGOWANY") + return } + if(localStorage.getItem('token') === null){//brak tokenu + this.isLogged = false + console.log("NIEZALOGOWANY") + return + } + console.log("JEST ZALOGOWANY") + this.isLogged = true + + } + }, + watch:{ + changeStatus(){ + this.checkIsUserLogged() } } diff --git a/frontend/app/src/views/Login.vue b/frontend/app/src/views/Login.vue index e0bf1a4..2615036 100644 --- a/frontend/app/src/views/Login.vue +++ b/frontend/app/src/views/Login.vue @@ -63,7 +63,8 @@ export default { login(){ if (this.$refs.form.validate()){ //valinnaj JS - axios.post("http://127.0.0.1:3000/api/loginUserView" , + axios.post("http://127.0.0.1:3000/api/loginUserView", + {"login": this.userLogin, "password": this.userPassword}, //DANE DO LOGOWANIA { crossdomain: true }) .then(response=>{ console.log("Response data: ", response.data); //printuje Tokena @@ -76,11 +77,14 @@ export default { var local = localStorage.getItem('token'); + console.log("______________________________TOKEN_____________________________") + console.log(localStorage.getItem('token')) var localU = localStorage.getItem('user'); //dodanie loginu do listy wszystkich zalogowanych użytkowników this.$store.dispatch('addLoggedUser', localStorage.getItem('user')) + axios.post("http://127.0.0.1:3000/api/updateLoggedUserView", {"login": this.userLogin} , //aktualizacja stanu uzytkownika w bazie mysql { crossdomain: true }) .then(response=>{