Commit 98e57750 authored by amandazk's avatar amandazk

Login / Logout

parent 650a1f83
<template>
<div id="formContent">
<h1>Login</h1>
<h2>Logado: {{loggedIn}}</h2>
<h2>Logado: {{ loggedIn }}</h2>
<!-- Login Form -->
<form>
<input
......@@ -39,30 +39,32 @@
</template>
<script>
import { mapActions, mapState } from 'vuex'
import { mapActions, mapState } from "vuex";
export default {
name: "Login",
data() {
return {
user: {}
}
user: {},
};
},
computed: {
...mapState('auth', ['loggedIn'])
...mapState("auth", ["loggedIn"]),
},
methods: {
...mapActions('auth', ['login']),
...mapActions("auth", ["login"]),
async submit() {
try {
await this.login(this.user)
await this.login(this.user);
// this.$router.push( { path: '/' })
} catch(error) {
console.log('Erro de Login: ', error)
} catch (error) {
console.log("Erro de Login: ", error);
}
}
}
},
// redireciona() {
// login(), this.$router.go();
// },
},
};
</script>
......@@ -180,7 +182,7 @@ input[type="reset"]:active {
transform: scale(0.95);
}
input[type="password"],
input[type="password"],
input[type="text"] {
background-color: #f6f6f6;
border: none;
......
......@@ -46,12 +46,20 @@
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<button v-if="isLoggedIn" class="btn btn-outline-dark my-2 my-sm-0" v-on:click="logout">
<a class="btn btn-outline-dark my-2 my-sm-0"
v-if="isLoggedIn"
v-on:click="logout"
href="/login"
>
Sair
</button>
<button v-else class="btn btn-outline-dark my-2 my-sm-0" v-on:click="login">
</a>
<a class="btn btn-outline-dark my-2 my-sm-0"
v-else
v-on:click="login"
href="/login"
>
Entrar
</button>
</a>
</form>
</div>
</nav>
......@@ -66,12 +74,12 @@ export default {
},
},
methods: {
// login() {
// window.location.replace("http://127.0.0.1:8000/accounts/login/");
// },
login() {
this.$router.go();
},
logout() {
window.localStorage.removeItem("psIfc");
window.location.replace("http://127.0.0.1:8000/");
this.$router.go();
},
},
};
......
......@@ -9,6 +9,7 @@ if (storage && storage.auth) {
var _user = {}
}
export const auth = {
namespaced: true,
state: {
......@@ -24,17 +25,9 @@ export const auth = {
}, (error) => {
commit('loginFailure')
return Promise.reject(error)
})
}
)
},
// logout () {
// localStorage.removeItem('psIfc')
// this.$router.push('/login')
// }
logout() {
window.localStorage.removeItem("psIfc");
window.location.replace("http://127.0.0.1:8000/")
}
},
mutations: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment