From eadfd0064d76f893be7b7186d90ee6cf34c257f5 Mon Sep 17 00:00:00 2001 From: p1905074 Date: Fri, 27 Nov 2020 08:35:19 +0100 Subject: [PATCH] =?UTF-8?q?envoie=20du=20formulaire=20=C3=A9dition=20de=20?= =?UTF-8?q?profil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/javascripts/profil.js | 21 +++++++++++++++++++++ sockets/profile/edit.js | 1 + 2 files changed, 22 insertions(+) create mode 100644 public/javascripts/profil.js diff --git a/public/javascripts/profil.js b/public/javascripts/profil.js new file mode 100644 index 0000000..c2c044b --- /dev/null +++ b/public/javascripts/profil.js @@ -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 = "/"; + } +}) \ No newline at end of file diff --git a/sockets/profile/edit.js b/sockets/profile/edit.js index 2fcaff5..99565a4 100644 --- a/sockets/profile/edit.js +++ b/sockets/profile/edit.js @@ -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;