From 439a9e289d1b045a1fccb0cc5d988fd1561b33d4 Mon Sep 17 00:00:00 2001 From: moepoi Date: Sun, 21 Nov 2021 13:42:38 +0700 Subject: [PATCH] Update forgot password --- ...change-password.css => reset-password.css} | 0 .../{change-password.js => reset-password.js} | 0 routes/index.js | 47 ++++++++++++++++--- views/layouts/footer.ejs | 4 +- views/layouts/header.ejs | 4 +- views/pages/forgot-password.ejs | 10 ++-- ...change-password.ejs => reset-password.ejs} | 14 +++--- 7 files changed, 56 insertions(+), 23 deletions(-) rename public/css/{change-password.css => reset-password.css} (100%) rename public/js/{change-password.js => reset-password.js} (100%) rename views/pages/{change-password.ejs => reset-password.ejs} (82%) 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.
-
+
- +
- +

Or Return to Login diff --git a/views/pages/change-password.ejs b/views/pages/reset-password.ejs similarity index 82% rename from views/pages/change-password.ejs rename to views/pages/reset-password.ejs index cb79fee..1420152 100644 --- a/views/pages/change-password.ejs +++ b/views/pages/reset-password.ejs @@ -1,23 +1,23 @@ -<%- include('../layouts/header.ejs', {title: 'Change Password', state: 'change-password'}); %> +<%- include('../layouts/header.ejs', {title: 'Reset Password', state: 'reset-password'}); %> - <%- include('../layouts/navbar.ejs', {types: 'v2', title: 'Change Password'}); %> + <%- include('../layouts/navbar.ejs', {types: 'v2', title: 'Reset Password'}); %>
-

Change Password

+

Reset Password

- +
@@ -44,8 +44,8 @@
- +

@@ -55,7 +55,7 @@
- <%- include('../layouts/footer.ejs', {state: 'change-password'}); %> + <%- include('../layouts/footer.ejs', {state: 'reset-password'}); %> \ No newline at end of file