1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
letu/sockets/profile/edit.js
2020-12-12 18:20:02 +01:00

23 lines
944 B
JavaScript

const models = require("../../models");
module.exports = socket => {
return async (data) => {
let user = await models.User.findByPk(socket.request.session.user.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;
user.newPassword = data.newPassword;
if (data.password && !user.checkPassword(data.password))
user.passwordHash = data.password;
socket.request.session.user = user;
socket.request.session.save();
socket.emit("profileEdit", user)
}
}
};