reset password wip
This commit is contained in:
@ -1,7 +1,13 @@
|
||||
const { addUser, loginUser, checkEmail , checkEmailDetails } = require("../functions/user");
|
||||
const {
|
||||
addUser,
|
||||
loginUser,
|
||||
checkEmail,
|
||||
checkEmailDetails,
|
||||
} = require("../functions/user");
|
||||
const { sendContactEmail } = require("../functions/nodeMail");
|
||||
const { generateUUID } = require("../functions/generateUUID");
|
||||
const { } = require("../functions/api");
|
||||
const { addPasswordResetToken } = require("../functions/api");
|
||||
const { sendResetPasswordEmail } = require("../functions/nodeMail");
|
||||
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
@ -59,14 +65,12 @@ router.post("/contact", async (req, res, next) => {
|
||||
let error = new Error("Email not found");
|
||||
error.status = 400;
|
||||
return next(error);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
//console.log(Res);
|
||||
sendContactEmail(req.body.email, req.body.name, req.body.message);
|
||||
return res.json({
|
||||
message: "Email sent successfully",
|
||||
});
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -76,47 +80,46 @@ router.post("/contact", async (req, res, next) => {
|
||||
|
||||
//reset
|
||||
router.post("/checkemail", async (req, res, next) => {
|
||||
try{
|
||||
|
||||
try {
|
||||
let Res = await checkEmail(req.body.email);
|
||||
if (!Res) {
|
||||
let error = new Error("Email not found");
|
||||
error.status = 400;
|
||||
return next(error);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
//user info lookup
|
||||
let data = await checkEmailDetails(req.body.email);
|
||||
//console.log(data);
|
||||
//token generation and insert into token table
|
||||
//token generation and insert into token table
|
||||
const token = await generateUUID();
|
||||
|
||||
let tokenRes = await addPasswordResetToken(data , token);
|
||||
let tokenRes = await addPasswordResetToken(data, token);
|
||||
|
||||
//email user with temp token link
|
||||
if (!tokenRes) return false;
|
||||
|
||||
//email logic to send reset password link
|
||||
|
||||
sendResetPasswordEmail(req.body.email, token);
|
||||
|
||||
return res.json({
|
||||
message: "Reset Password Link has successfully sent to your email!",
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}catch (error){
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/resetpassword/:token", async (req, res, next) => {
|
||||
//pass token to reset password page
|
||||
|
||||
});
|
||||
|
||||
//reset password
|
||||
router.post("/resetpassword", async (req, res, next) => {
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
|
||||
/*
|
||||
router.get('/login/resetpassword/:token', async function(req, res, next){
|
||||
res.render('reset_password', {});
|
||||
});
|
||||
|
||||
*/
|
||||
|
Reference in New Issue
Block a user