Added Signup button as well

nodejs
Aravind142857 2 years ago
parent decfc44592
commit c6dec7838a

@ -32,7 +32,7 @@
<a href="#head" class="block mt-4 lg:inline-block lg:mt-0 text-teal-200 hover:text-black mr-4 hover:bg-gray-200 hover:border hover:border-gray-200 hover:rounded text-teal-200 py-1 px-3"> <a href="#head" class="block mt-4 lg:inline-block lg:mt-0 text-teal-200 hover:text-black mr-4 hover:bg-gray-200 hover:border hover:border-gray-200 hover:rounded text-teal-200 py-1 px-3">
C C
</a> </a>
<a href="/index.html" class="block mt-4 lg:inline-block lg:mt-0 bg-blue-600 brightness-125 border border-blue-500 rounded text-teal-200 hover:text-black py-1 px-3"> <a href="/index_1.html" class="block mt-4 lg:inline-block lg:mt-0 bg-blue-600 brightness-125 border border-blue-500 rounded text-teal-200 hover:text-black py-1 px-3">
Products (Form) Products (Form)
</a> </a>
</div> </div>

@ -33,18 +33,44 @@ app.use(sessions({
})) }))
app.use(cookieParser()); app.use(cookieParser());
var session; 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) { app.get('/', function(req, res) {
console.log("Moving to a diff site");
var tagline; var tagline;
var signup;
var loc;
if (req.session.userId) { if (req.session.userId) {
tagline = "logout"; tagline = "logout";
signup = "hidden";
loc = "__logout";
} else { } else {
tagline = "log in"; tagline = "log in";
loc = "login.html";
} }
res.render('pages/index', { res.render('pages/index', {
tagline: tagline tagline: tagline,
signup: signup,
loc: loc
}); });
}) })
app.use(express.static(staticPath));
const GLINK_SIZE = 6; const GLINK_SIZE = 6;
function getRandomGLink() { function getRandomGLink() {
let glink = ""; 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); 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) => { // app.get('/', (request, response) => {
// response.render("index.html"); // response.render("index_1.html");
// }) // })
app.get('/node_modules/', (request, response) => { app.get('/node_modules/', (request, response) => {
response.redirect("./error.html"); response.redirect("./error.html");
@ -215,9 +241,27 @@ app.get('/__logout', function(req, res, cb) {
console.log(req.session); console.log(req.session);
console.log(session); console.log(session);
req.session.destroy(); 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"); console.log("done");
res.end();
}) })
app.post('/__check', function(req, res) { app.post('/__check', function(req, res) {
let user_latitude = req.body.latitude; 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"); console.log("Entered signup");
let email = req.body.email; let email = req.body.email;
let password = req.body.password; let password = req.body.password;
@ -312,15 +356,22 @@ app.post('/__login', function(req, res, cb) {
console.log(req.session); console.log(req.session);
var tagline; var tagline;
var signup;
var loc;
if (req.session.userId) { if (req.session.userId) {
tagline = "logout"; tagline = "logout";
signup = "hidden";
loc = "/__logout"
} else { } else {
tagline = "log in"; tagline = "log in";
loc = "login.html";
} }
res.render('pages/index', { res.render('pages/index', {
tagline: tagline tagline: tagline,
signup: signup,
loc: loc
}); });
/*res.redirect("/index.html");*/ /*res.redirect("/index_1.html");*/
res.end(); res.end();
} else { } else {
console.log("Wrong password"); console.log("Wrong password");

@ -32,12 +32,18 @@
<a href="#head" class="block mt-4 lg:inline-block lg:mt-0 text-teal-200 hover:text-black mr-4 hover:bg-gray-200 hover:border hover:border-gray-200 hover:rounded text-teal-200 py-1 px-3"> <a href="#head" class="block mt-4 lg:inline-block lg:mt-0 text-teal-200 hover:text-black mr-4 hover:bg-gray-200 hover:border hover:border-gray-200 hover:rounded text-teal-200 py-1 px-3">
C C
</a> </a>
<a href="/index.html" class="block mt-4 lg:inline-block lg:mt-0 bg-blue-600 brightness-125 border border-blue-500 rounded text-teal-200 hover:text-black py-1 px-3"> <a href="index.html" class="block mt-4 lg:inline-block lg:mt-0 bg-blue-600 brightness-125 border border-blue-500 rounded text-teal-200 hover:text-black py-1 px-3">
Products (Form) Products (Form)
</a> </a>
</div> </div>
<div>
<a href="signup.html" class="inline-block <%= signup %> text-sm px-4 py-2 leading-none border rounded text-white border-white hover:border-transparent hover:text-teal-500 hover:bg-white mt-4 lg:mt-0 mr-4">
signup
</a>
</div>
<div> <div>
<a href="/__logout" class="inline-block text-sm px-4 py-2 leading-none border rounded text-white border-white hover:border-transparent hover:text-teal-500 hover:bg-white mt-4 lg:mt-0"> <a href="<%= loc %>" class="inline-block text-sm px-4 py-2 leading-none border rounded text-white border-white hover:border-transparent hover:text-teal-500 hover:bg-white mt-4 lg:mt-0">
<%= tagline %> <%= tagline %>
</a> </a>
</div> </div>
@ -100,9 +106,9 @@
</form> </form>
<hr> <hr>
<img src="./images/cat.gif"> <img src="images/cat.gif">
<p id="footer" class="object-none object-bottom">Insert Footer Here</p> <p id="footer" class="object-none object-bottom">Insert Footer Here</p>
<script src="./src/index.js"></script> <script src="src/index.js"></script>
</div> </div>
</body> </body>

Loading…
Cancel
Save