Commit adaaba7e authored by Zohten's avatar Zohten

login working

parent df30501c
......@@ -8,8 +8,8 @@ GET http://localhost/index.php/user/3
POST http://localhost/index.php/login
{
"login": "dupontd95",
"pwd": "hasheddupontpwd"
"login": "testtest",
"pwd": "$2a$10$4AAhcsd4FpiPvUS718BemuGivzgRcsgxWbaSNdD.dK4wNwJAn.lQO"
}
### Tenter de récupérer un token utilisateur bloqué
......
......@@ -3,7 +3,7 @@
<page-title pagetitle="Se Connecter"/>
<form action="#" @submit.prevent="onSubmit">
<div class="form-content">
<text-input id="mail" label="Email"/>
<text-input id="login" label="Pseudo"/>
<pwd-input id="password" label="Mot de passe"/>
<checkbox-input id="remember" label="Se souvenir de moi"/>
......@@ -16,6 +16,7 @@
</template>
<script>
import bcrypt from 'bcryptjs'
import PageTitle from '@/components/PageTitle.vue'
import SvgButton from '@/components/SvgButton.vue'
import TextInput from '@/components/form/TextInput.vue'
......@@ -30,16 +31,47 @@ export default {
PwdInput,
CheckboxInput
},
data() {
return {
showNotFilledError : false,
}
},
methods: {
onSubmit: function(event){
onSubmit: async function(event){
if (event.submitter.id=='back') {
this.$router.push('/');
}
// Test if all fields are filled
this.showNotFilledError = (
document.getElementById('login').value == ''
|| document.getElementById('password').value == ''
);
if (this.showNotFilledError) {
return;
}
// Get auth token if everything is okay
if (event.submitter.id=='validate') {
let request = await fetch(this.$apiRoot+'/login',
{
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({
login: document.getElementById('login').value,
pwd: bcrypt.hashSync(document.getElementById('password').value, "$2a$10$4AAhcsd4FpiPvUS718Bemu"),
})
}); //creating the content and sending the request
let response = await request;
if (response.ok){
this.$router.push('lobby');
}
}
}
}
}
</script>
......
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