Add profile edit
This commit is contained in:
parent
e736c62fde
commit
6477d8e074
2 changed files with 23 additions and 0 deletions
|
@ -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
22
sockets/profile/edit.js
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue