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/email/setPassword.js

20 lines
713 B
JavaScript
Raw Normal View History

const models = require("../../models");
module.exports = socket => {
return async (data) => {
let user = await models.User.findOne({where: {passwordToken: data.token}});
if (!user)
socket.emit("setPassword", {error: {message: "invalid_token"}})
else if (user.passwordTokenDate && ((new Date().getTime() - user.passwordTokenDate.getTime()) / 1000 > 3600))
socket.emit("setPassword", {error: {message: "expired_token"}});
else {
user.passwordToken = null;
user.passwordTokenDate = null;
user.passwordHash = data.password;
await user.save();
socket.emit("setPassword", true);
}
}
}