diff --git a/public/css/change-password.css b/public/css/reset-password.css similarity index 100% rename from public/css/change-password.css rename to public/css/reset-password.css diff --git a/public/js/change-password.js b/public/js/reset-password.js similarity index 100% rename from public/js/change-password.js rename to public/js/reset-password.js diff --git a/routes/index.js b/routes/index.js index 030d04e..e298e14 100644 --- a/routes/index.js +++ b/routes/index.js @@ -161,18 +161,51 @@ router.route("/checkout") }); }); -router.get("/forgot-password", (_req, res) => { - res.render("pages/forgot-password"); -}); + +router.route("/reset-password") + .get((req, res) => { + if (!req.query.token) { + res.redirect("/"); + } else { + res.render("pages/reset-password", { + token: req.query.token + }) + } + }) + .post((req, res) => { + controller.reset_password(req.query.token, req.body.password).then((data) => { + if (data[0] == 200) { + res.render("pages/register-verification-completed"); + } else { + res.redirect("/"); + } + }); + }); + +router.route("/forgot-password") + .get((req, res) => { + auth.session_converter(req.cookies.session_token).then((key) => { + if (key != null) { + res.redirect("/"); + } else { + res.render("pages/forgot-password"); + } + }); + }) + .post((req, res) => { + controller.request_reset_password(req.body.email).then((data) => { + if (data[0] == 200) { + res.render("pages/register-verification-sent"); + } else { + res.redirect("/forgot-password"); + } + }); + }); router.get("/otp", (_req, res) => { res.render("pages/otp"); }); -router.get("/change-password", (_req, res) => { - res.render("pages/change-password"); -}); - router.get("/products", (req, res) => { auth.session_converter(req.cookies.session_token).then((key) => { if (key != null) { diff --git a/views/layouts/footer.ejs b/views/layouts/footer.ejs index ddd9a00..d3dc1e9 100644 --- a/views/layouts/footer.ejs +++ b/views/layouts/footer.ejs @@ -38,8 +38,8 @@ <% } else if(state == "login") { %> -<% } else if(state == "change-password") { %> - +<% } else if(state == "reset-password") { %> + <% } else if(state == "register") { %> <% } else if(state == "otp") { %> diff --git a/views/layouts/header.ejs b/views/layouts/header.ejs index 19ad87c..01254f0 100644 --- a/views/layouts/header.ejs +++ b/views/layouts/header.ejs @@ -41,8 +41,8 @@ <% } else if(state == "forgot-password") { %> - <% } else if(state == "change-password") { %> - + <% } else if(state == "reset-password") { %> + <% } else if(state == "otp") { %> <% } else if(state == "faq") { %> diff --git a/views/pages/forgot-password.ejs b/views/pages/forgot-password.ejs index f2e1909..47290a5 100644 --- a/views/pages/forgot-password.ejs +++ b/views/pages/forgot-password.ejs @@ -17,15 +17,15 @@ Enter your email to receive a link to reset your password.