Commit adaaba7e authored by Zohten's avatar Zohten

login working

parent df30501c
...@@ -8,8 +8,8 @@ GET http://localhost/index.php/user/3 ...@@ -8,8 +8,8 @@ GET http://localhost/index.php/user/3
POST http://localhost/index.php/login POST http://localhost/index.php/login
{ {
"login": "dupontd95", "login": "testtest",
"pwd": "hasheddupontpwd" "pwd": "$2a$10$4AAhcsd4FpiPvUS718BemuGivzgRcsgxWbaSNdD.dK4wNwJAn.lQO"
} }
### Tenter de récupérer un token utilisateur bloqué ### Tenter de récupérer un token utilisateur bloqué
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<page-title pagetitle="Se Connecter"/> <page-title pagetitle="Se Connecter"/>
<form action="#" @submit.prevent="onSubmit"> <form action="#" @submit.prevent="onSubmit">
<div class="form-content"> <div class="form-content">
<text-input id="mail" label="Email"/> <text-input id="login" label="Pseudo"/>
<pwd-input id="password" label="Mot de passe"/> <pwd-input id="password" label="Mot de passe"/>
<checkbox-input id="remember" label="Se souvenir de moi"/> <checkbox-input id="remember" label="Se souvenir de moi"/>
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
</template> </template>
<script> <script>
import bcrypt from 'bcryptjs'
import PageTitle from '@/components/PageTitle.vue' import PageTitle from '@/components/PageTitle.vue'
import SvgButton from '@/components/SvgButton.vue' import SvgButton from '@/components/SvgButton.vue'
import TextInput from '@/components/form/TextInput.vue' import TextInput from '@/components/form/TextInput.vue'
...@@ -30,16 +31,47 @@ export default { ...@@ -30,16 +31,47 @@ export default {
PwdInput, PwdInput,
CheckboxInput CheckboxInput
}, },
data() {
return {
showNotFilledError : false,
}
},
methods: { methods: {
onSubmit: function(event){ onSubmit: async function(event){
if (event.submitter.id=='back') { if (event.submitter.id=='back') {
this.$router.push('/'); 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') { 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'); this.$router.push('lobby');
} }
} }
} }
}
} }
</script> </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