poprawienie paska na zaloguj/wyloguj
This commit is contained in:
parent
bae651c4e3
commit
10d5ce809a
@ -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")
|
||||
|
@ -55,9 +55,11 @@
|
||||
</v-menu>
|
||||
|
||||
<v-btn flat color="grey" @click="userAction">
|
||||
<span v-if="isLogged">Wyloguj
|
||||
<span v-if="!snackbarLogout">Wyloguj
|
||||
<!-- jeśli jest zalogowany to pokazuj "wyloguj" -->
|
||||
</span>
|
||||
<span v-if="!isLogged">Zaloguj</span>
|
||||
<span v-if="snackbarLogout">Zaloguj</span>
|
||||
<!-- jeśli się wylogował to pokazuj "zaloguj" -->
|
||||
<v-icon right>exit_to_app</v-icon>
|
||||
</v-btn>
|
||||
</v-toolbar>
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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=>{
|
||||
|
Loading…
Reference in New Issue
Block a user