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;