envoie du formulaire édition de profil
This commit is contained in:
parent
768c982293
commit
eadfd0064d
2 changed files with 22 additions and 0 deletions
21
public/javascripts/profil.js
Normal file
21
public/javascripts/profil.js
Normal 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 = "/";
|
||||||
|
}
|
||||||
|
})
|
|
@ -12,6 +12,7 @@ module.exports = socket => {
|
||||||
user.firstName = data.firstName;
|
user.firstName = data.firstName;
|
||||||
if (data.lastName !== user.lastName)
|
if (data.lastName !== user.lastName)
|
||||||
user.lastName = data.lastName;
|
user.lastName = data.lastName;
|
||||||
|
user.newPassword = data.newPassword;
|
||||||
if (data.password && !user.checkPassword(data.password))
|
if (data.password && !user.checkPassword(data.password))
|
||||||
user.passwordHash = data.password
|
user.passwordHash = data.password
|
||||||
socket.request.session.user = user;
|
socket.request.session.user = user;
|
||||||
|
|
Reference in a new issue