Skip to content

Commit

Permalink
Add cookie checking again
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdawww committed Mar 14, 2021
1 parent 4015e5a commit c292426
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 33 deletions.
18 changes: 1 addition & 17 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ app.use(session({
resave: true
}));

app.use(cookieParser());
app.use(flash());
/* Routing to specific JS file */
var indexRouter = require('./routes/index');
Expand All @@ -34,7 +35,6 @@ hbs.registerPartials(path.join(__dirname, 'views/partials'));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(sassMiddleware({
src: path.join(__dirname, 'public'),
dest: path.join(__dirname, 'public'),
Expand Down Expand Up @@ -66,20 +66,4 @@ app.use(function(err, req, res, next) {
res.render('error');
});

/* Controllers for javascript forms and database connection */
let authenticateController=require('./public/controllers/authenticate-controller');
let registerController=require('./public/controllers/register-controller');
let ticketsController=require('./public/controllers/tickets-controller');

/* route to handle login and registration */
/*
app.post('/api/register',registerController.register);
app.post('/api/authenticate',authenticateController.authenticate);
app.post('/api/createTicket', ticketsController.createTicket);
app.post('/controllers/register-controller', registerController.register);
app.post('/controllers/authenticate-controller', authenticateController.authenticate);
app.post('/controllers/tickets-controller', ticketsController.createTicket);
*/

module.exports = app;
1 change: 1 addition & 0 deletions public/controllers/authenticate-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports.authenticate=function(req,res){
}
else {
if (password === columns[0].value) {
res.cookie('username', username);
req.flash('error', "" );
req.flash('errorMsg', "");
res.redirect('/');
Expand Down
1 change: 1 addition & 0 deletions public/controllers/register-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports.register=function(req,res){
return;
} else {
console.log(rowCount + " rows affected.");
res.cookie('username', username);
req.flash('error', "" );
req.flash('errorMsg', "");
res.redirect('/');
Expand Down
5 changes: 2 additions & 3 deletions public/stylesheets/modal.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/stylesheets/tickets.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var express = require('express');
var router = express.Router();
var authenticateController=require("../public/controllers/authenticate-controller");
var registerController=require("../public/controllers/register-controller");
var ticketsController=require("../public/controllers/tickets-controller");
var contactsController=require("../public/controllers/send-email");

/* GET home page. */
Expand All @@ -27,13 +26,6 @@ router.get('/login', function (req, res) {
res.sendFile( __dirname + "/" + "login.html" );
});

/* route to handle login and registration */
/*
router.post('/api/register',registerController.register);
router.post('/api/authenticate',authenticateController.authenticate);
router.post('/api/createTicket',ticketsController.createTicket);
*/

router.post('/register-controller.js', registerController.register);
router.post('/authenticate-controller.js', authenticateController.authenticate);
Expand Down
17 changes: 13 additions & 4 deletions routes/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ let ticketsController=require("../public/controllers/tickets-controller");

module.exports = function(app){
app.get('/tickets', function(req, res){
res.render('tickets', {
title: 'Tickets - Mutual Aid',
layout: 'tickets'
});
if ('username' in req.cookies) {
console.log('username found: ' + req.cookies.username);
res.render('tickets', {
title: 'Tickets - Mutual Aid',
layout: 'tickets'
});
} else {
console.log('no username found');
res.render('ticket-error', {
title: 'Tickets - No Access',
layout: 'tickets'
})
}
});

router.post('/tickets-controller.js', ticketsController.createTicket);
Expand Down
19 changes: 19 additions & 0 deletions views/ticket-error.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>{{title}}</title>
<link rel="stylesheet" href="/stylesheets/footer.css">
<link rel="stylesheet" href="/stylesheets/header.css">
<link rel="stylesheet" href="/stylesheets/modal.css">
</head>
<body>

{{> header}}

<div id='ticket-wrapper'>
<div id='error'>nothing to see here </div>
</div>

{{> footer}}

</body>
</html>

0 comments on commit c292426

Please sign in to comment.