1
0
Fork 0

Add profile edit

This commit is contained in:
Ethanell 2020-11-02 17:18:03 +01:00
parent e736c62fde
commit 6477d8e074
2 changed files with 23 additions and 0 deletions

View file

@ -5,5 +5,6 @@ module.exports = socket => {
socket.on("checkResend", require("./email/checkResend")(socket)); socket.on("checkResend", require("./email/checkResend")(socket));
socket.on("forgotPassword", require("./email/forgotPassword")(socket)); socket.on("forgotPassword", require("./email/forgotPassword")(socket));
socket.on("setPassword", require("./email/setPassword")(socket)); socket.on("setPassword", require("./email/setPassword")(socket));
socket.on("profileEdit", require("./profile/edit")(socket));
socket.emit("connected"); socket.emit("connected");
} }

22
sockets/profile/edit.js Normal file
View file

@ -0,0 +1,22 @@
const models = require("../../models");
module.exports = socket => {
return async (data) => {
let user = await models.User.findByPk(data.email);
if (!user)
socket.emit("profileEdit", {error: {message: "not_found"}});
else if (!user.checkPassword(data.oldPassword))
socket.emit("profileEdit", {error: {message: "invalid_password"}})
else {
if (data.firstName !== user.firstName)
user.firstName = data.firstName;
if (data.lastName !== user.lastName)
user.lastName = data.lastName;
if (data.password && !user.checkPassword(data.password))
user.passwordHash = data.password
socket.request.session.user = user;
socket.request.session.save();
socket.emit("profileEdit", user)
}
}
}