From c6dec7838a23f3e0de2ee63846063b56ea9e1674 Mon Sep 17 00:00:00 2001 From: Aravind142857 Date: Tue, 27 Jun 2023 02:11:26 -0500 Subject: [PATCH] Added Signup button as well --- public/{index.html => index_1.html} | 2 +- result.js | 67 +++++++++++++++++++++++++---- views/pages/index.ejs | 14 ++++-- 3 files changed, 70 insertions(+), 13 deletions(-) rename public/{index.html => index_1.html} (97%) diff --git a/public/index.html b/public/index_1.html similarity index 97% rename from public/index.html rename to public/index_1.html index fc4eed4..1a25efd 100644 --- a/public/index.html +++ b/public/index_1.html @@ -32,7 +32,7 @@ C - + Products (Form) diff --git a/result.js b/result.js index 75879b7..a312285 100644 --- a/result.js +++ b/result.js @@ -33,18 +33,44 @@ app.use(sessions({ })) app.use(cookieParser()); var session; +app.use(express.static(staticPath)); +app.get('/bruh', function(req, res) { + var tagline; + var signup; + var loc; + if (req.session.userId) { + tagline = "logout"; + signup = "hidden"; + loc = "/__logout"; + } else { + tagline = "log in"; + loc = "login.html" + } + res.render('pages/index', { + tagline: tagline, + signup: signup, + loc: loc + }); +}) app.get('/', function(req, res) { + console.log("Moving to a diff site"); var tagline; + var signup; + var loc; if (req.session.userId) { tagline = "logout"; + signup = "hidden"; + loc = "__logout"; } else { tagline = "log in"; + loc = "login.html"; } res.render('pages/index', { - tagline: tagline + tagline: tagline, + signup: signup, + loc: loc }); }) -app.use(express.static(staticPath)); const GLINK_SIZE = 6; function getRandomGLink() { let glink = ""; @@ -120,7 +146,7 @@ function calculateDistance(lat1, lat2, long1, long2) { return (2 * Math.asin(Math.sqrt(Math.pow(Math.sin((lat2 - lat1)/2), 2) + Math.pow(Math.sin((long2 - long1)/2), 2) * Math.cos(lat1) * Math.cos(lat2))) * RADIUS_OF_EARTH_IN_MILES); } // app.get('/', (request, response) => { -// response.render("index.html"); +// response.render("index_1.html"); // }) app.get('/node_modules/', (request, response) => { response.redirect("./error.html"); @@ -215,9 +241,27 @@ app.get('/__logout', function(req, res, cb) { console.log(req.session); console.log(session); req.session.destroy(); - res.redirect('/login.html'); + var tagline; + var signup; + var loc; + console.log(req.session); + if ( req.session && req.session.userId) { + console.log("session valid"); + tagline = "logout"; + signup = "hidden"; + loc = "__logout"; + } else { + console.log("session invalid"); + tagline = "log in"; + loc = "/login.html"; + } + res.render('pages/index', { + tagline: tagline, + signup: signup, + loc: loc + }); console.log("done"); - res.end(); + }) app.post('/__check', function(req, res) { let user_latitude = req.body.latitude; @@ -247,7 +291,7 @@ app.post('/__check', function(req, res) { } }) }) -app.post('/__signup', function(req, res, cb) { +app.get('/__signup', function(req, res, cb) { console.log("Entered signup"); let email = req.body.email; let password = req.body.password; @@ -312,15 +356,22 @@ app.post('/__login', function(req, res, cb) { console.log(req.session); var tagline; + var signup; + var loc; if (req.session.userId) { tagline = "logout"; + signup = "hidden"; + loc = "/__logout" } else { tagline = "log in"; + loc = "login.html"; } res.render('pages/index', { - tagline: tagline + tagline: tagline, + signup: signup, + loc: loc }); - /*res.redirect("/index.html");*/ + /*res.redirect("/index_1.html");*/ res.end(); } else { console.log("Wrong password"); diff --git a/views/pages/index.ejs b/views/pages/index.ejs index 07ae7f4..e617394 100644 --- a/views/pages/index.ejs +++ b/views/pages/index.ejs @@ -32,12 +32,18 @@ C - + Products (Form) + +
+ +
- + <%= tagline %>
@@ -100,9 +106,9 @@
- + - +