utiliser l'objet Utilisateur dans le login

front
Gwenael PLANCHON 1 year ago
parent 22447ce309
commit f9300d471d

@ -1,15 +1,13 @@
<script>
import { REST_API } from '@/assets/const'
import { RouterLink } from 'vue-router'
import { Utilisateur } from "@/data/utilisateur"
export default {
methods:{
login: function (event){event.stopPropagation()
let donnees=Object.fromEntries(new FormData(formajouter))
const donneesJson=JSON.stringify(donnees)
console.log(donnees)
fetch(REST_API+"/utilisateur/connexion", {method:"POST", body:donneesJson, headers:{"Content-Type":"application/json"}}).then(response=>console.log(response))
login(){
const utilisateur=new Utilisateur(Object.fromEntries(new FormData(formajouter)))
utilisateur.login().then(response=>console.log(response))
}
}
}

@ -18,7 +18,11 @@ export class Utilisateur extends DataObject{
return new this(await response.json())
}
async login(){
const response = await fetch(`${REST_API}/utilisateur/connexion`, {method:"POST" ,headers:{"Content-Type":"application/json"}, body:this})
const response = await fetch(`${REST_API}/utilisateur/connexion`,{
method:"POST",
headers:{"Content-Type":"application/json"},
body:JSON.stringify(this)
})
return new this(await response.json())
}
}

Loading…
Cancel
Save