Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working #13

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# assignment_css_garden_of_good_and_evil
Create a CSS garden that adapts to your whims.

by Ed & Stephanie
61 changes: 61 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const express = require("express");
const app = express();
const exphbs = require("express-handlebars");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");

app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(__dirname + '/public'));

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');

app.get('/', (req, res) => {
let options = {
alignment: 'good',
good: true,
evil: false,
};
if (req.cookies.alignment === "good") {
options.alignment = "good";
options.good = true;
options.evil = false;
} else if (req.cookies.alignment === "evil") {
options.alignment = "evil";
options.good = false;
options.evil = true;
}
options['favorite-food'] = req.cookies['favorite-food'];
options["favoriteColor"] = req.cookies.favoriteColor || "white";
options.insanity = req.cookies.insanity || 2;

if (options.insanity === "3") {
options.insane = true;
} else {
options.insane = false;
}

if (options.insanity === "1") {
options.boring = true;
} else {
options.boring = false;
}


res.render('index', options);
})

app.listen(3000)

app.post('/', (req, res) => {
res.cookie("alignment", req.body.alignment)
if (req.body['favorite-food']) {
res.cookie("favorite-food", req.body['favorite-food'])
}
if (req.body.favoriteColor) {
res.cookie("favoriteColor", req.body.favoriteColor);
}
res.cookie("insanity", req.body.insanity);
res.redirect("/");
})
Loading