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-11-02 17:18:03 +01:00

22 lines
869 B
JavaScript

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)
}
}
}