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/utils/emailCheck.js

28 lines
825 B
JavaScript
Raw Permalink Normal View History

2020-11-02 13:43:12 +01:00
let crypto = require("crypto");
let models = require("../../models");
let Message = require("emailjs").Message;
const config = require("../../config/config.json");
module.exports = async (socket, user, callBack) => {
let token = crypto.randomBytes(16).toString("hex");
while (await models.User.findOne({where: {emailToken: token}}))
token = crypto.randomBytes(16).toString("hex");
user.emailToken = token;
await user.save();
socket.server.mailClient.send( new Message({
text: `${config.email.mailPath}/email/check?token=${token}`,
from: config.email.from,
to: user.email,
subject: "Email check"
}), (err, message) => {
if (err)
socket.emit("register", null);
else
if (callBack)
callBack();
});
};