-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp
70 lines (69 loc) · 2.18 KB
/
temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// @ route POST api/auth
// @desc Reset password
// @access Public
router.post(
"/reset_password",
[check("password", "Password is required").exists()],
async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const { password } = req.body;
const { JWT_SECRET } = process.env;
try {
const { email } = jwt.verify(JWT_SECRET, req.query.token)
console.log(email)
// let user = await User.findOne({ email });
// if (!user) {
// return res
// .status(400)
// .json({ msg: "This email address does not have an account with us" });
// }
// const payload = {
// email: user.email,
// };
// jwt.sign(
// payload,
// JWT_SECRET,
// {
// expiresIn: 360000,
// },
// (err, token) => {
// if (err) throw err;
// try {
// const emailText = `Hi ${user.name}....... click https://${
// req.headers.x - forwarded - host
// }/reset_password?token=${token} to reset password. This token will expire in 3 minutes`;
// const mailOptions = {
// text: emailText,
// to: payload.email,
// from: "[email protected]",
// subject: "Change your Password",
// };
// const { EMAIL_PASS } = process.env;
// const transporter = nodemailer.createTransport({
// service: "gmail",
// auth: {
// user: "[email protected]",
// pass: EMAIL_PASS,
// },
// });
// transporter.sendMail(mailOptions, function (error, info) {
// if (error) {
// console.log(error);
// } else {
// console.log("Email sent: " + info.response);
// }
// });
// } catch (err) {
// console.log(err);
// }
// }
// );
} catch (err) {
console.log("error" + err.message);
res.status(500).send("Server Error");
}
}
);