1
0
Fork 0

envoie du formulaire édition de profil

This commit is contained in:
p1905074 2020-11-27 08:35:19 +01:00
parent 768c982293
commit eadfd0064d
2 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1,21 @@
let socket = io.connect();
document.getElementById("editprofil").addEventListener("submit", e=>{
e.preventDefault();
socket.emit("profileEdit", {
"email": mail,
"firstName": document.getElementById("firstname-input").value,
"lastName": document.getElementById("lastname-input").value,
"newPassword": document.getElementById("new-password").value,
"password": document.getElementById("password").value
});
});
socket.on("profileEdit", data=>{
if(data.error){
alert(data.error.message);
}else{
window.location.href = "/";
}
})

View file

@ -12,6 +12,7 @@ module.exports = socket => {
user.firstName = data.firstName;
if (data.lastName !== user.lastName)
user.lastName = data.lastName;
user.newPassword = data.newPassword;
if (data.password && !user.checkPassword(data.password))
user.passwordHash = data.password
socket.request.session.user = user;