-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Abu Darda
committed
Sep 21, 2018
0 parents
commit d21894a
Showing
24 changed files
with
976 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const express = require("express"), | ||
app = express(), | ||
bodyParser = require("body-parser"), | ||
mongoose = require("mongoose"), | ||
passport = require("passport"), | ||
LocalStrategy = require("passport-local"), | ||
flash = require("connect-flash"), | ||
methodOverride = require("method-override"), | ||
Campground = require("./models/campground"), | ||
User = require("./models/user"), | ||
Comment = require("./models/comment"), | ||
seedDB = require("./seeds") | ||
|
||
// REQUIRING ROUTES FILES | ||
const campgroundRoutes = require("./routes/campgrounds"), | ||
commentRoutes = require("./routes/comments"), | ||
authRoutes = require("./routes/auth"); | ||
|
||
mongoose.connect('mongodb://localhost:27017/yelp_camp', { useNewUrlParser: true }); | ||
app.use(bodyParser.urlencoded({extended: true})); | ||
app.set("view engine", "ejs"); | ||
app.use(express.static(__dirname + "/public")); | ||
app.use(methodOverride("_method")); | ||
app.use(flash()); | ||
// seedDB(); | ||
|
||
// PASSPORT CONFIGURATION | ||
app.use(require("express-session")({ | ||
secret: "hey its me", | ||
resave: false, | ||
saveUninitialized: false | ||
})); | ||
app.use(passport.initialize()); | ||
app.use(passport.session()); | ||
passport.use(new LocalStrategy(User.authenticate())); | ||
passport.serializeUser(User.serializeUser()); | ||
passport.deserializeUser(User.deserializeUser()); | ||
|
||
app.use(function(req, res, next){ | ||
res.locals.currentUser = req.user; | ||
res.locals.error = req.flash("error"); | ||
res.locals.success = req.flash("success"); | ||
next(); | ||
}); | ||
|
||
app.use(campgroundRoutes); | ||
app.use("/campgrounds/:id/comments",commentRoutes); | ||
app.use(authRoutes); | ||
|
||
app.listen(process.env.PORT, process.env.IP, function(){ | ||
console.log("The YelpCamp server has started..."); | ||
}); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
let Campground = require("../models/campground"); | ||
let Comment = require("../models/comment"); | ||
|
||
// all middleware goes here | ||
let middlewareObj = {}; | ||
|
||
middlewareObj.checkCampOwnership = function(req, res, next){ | ||
// is the user logged in | ||
if(req.isAuthenticated()){ | ||
Campground.findById(req.params.id, function(err, foundCampground){ | ||
if(err || !foundCampground){ | ||
req.flash("Error", "Error 400 Campground doesn't exist."); | ||
res.redirect("back") | ||
} else { | ||
// does the user owned the campground | ||
if(foundCampground.author.id.equals(req.user._id)){ | ||
next(); | ||
} else { | ||
req.flash("Error", "You don't have permission to do that!"); | ||
res.redirect("back"); | ||
} | ||
} | ||
}); | ||
} else { | ||
req.flash("error", "You need to be logged in first!"); | ||
res.redirect("back"); | ||
} | ||
} | ||
|
||
middlewareObj.checkCommentOwnership = function(req, res, next){ | ||
// is the user logged in | ||
if(req.isAuthenticated()){ | ||
Comment.findById(req.params.comment_id, function(err, foundComment){ | ||
if(err || !foundComment){ | ||
req.flash("error", "Comment doesn't exist"); | ||
res.redirect("/campgrounds") | ||
} else { | ||
// does the user owned the comment | ||
if(foundComment.author.id.equals(req.user._id)){ | ||
next(); | ||
} else { | ||
req.flash("error", "You don't have permission!"); | ||
res.redirect("back"); | ||
} | ||
} | ||
}); | ||
} else { | ||
req.flash("error", "You need to be Logged in first!"); | ||
res.redirect("back"); | ||
} | ||
}; | ||
|
||
middlewareObj.isLoggedIn = function(req, res, next){ | ||
// middleware isLoggedIn | ||
if(req.isAuthenticated()){ | ||
return next(); | ||
} | ||
req.flash("error", "You need to be logged in first!"); | ||
res.redirect("/login"); | ||
} | ||
|
||
module.exports = middlewareObj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
let mongoose = require("mongoose") | ||
|
||
|
||
// SCHEMA SETUP | ||
let campgroundSchema = new mongoose.Schema({ | ||
name: String, | ||
price: String, | ||
image: String, | ||
description: String, | ||
author: { | ||
id: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "User" | ||
}, | ||
username: String | ||
}, | ||
comments: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "Comment" | ||
} | ||
] | ||
}); | ||
|
||
module.exports = mongoose.model("Campground", campgroundSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
let mongoose = require("mongoose"); | ||
|
||
let commentSchema = mongoose.Schema({ | ||
text: String, | ||
author: { | ||
id:{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "User" | ||
}, | ||
username: String | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model("Comment", commentSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const mongoose = require("mongoose"), | ||
passportLocalMongoose = require("passport-local-mongoose"); | ||
|
||
let UserSchema = new mongoose.Schema({ | ||
username: String, | ||
password: String | ||
}); | ||
|
||
UserSchema.plugin(passportLocalMongoose); | ||
|
||
module.exports = mongoose.model("User", UserSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "v1", | ||
"version": "1.0.0", | ||
"description": "YelpCamp v1", | ||
"main": "app.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Abu", | ||
"license": "ISC", | ||
"dependencies": { | ||
"body-parser": "^1.18.3", | ||
"connect-flash": "^0.1.1", | ||
"ejs": "^2.6.1", | ||
"express": "^4.16.3", | ||
"express-session": "^1.15.6", | ||
"method-override": "^3.0.0", | ||
"mongoose": "^5.2.8", | ||
"passport": "^0.4.0", | ||
"passport-local": "^1.0.0", | ||
"passport-local-mongoose": "^5.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
.form { | ||
position: relative; | ||
z-index: 1; | ||
background: #FFFFFF; | ||
max-width: 360px; | ||
margin: 0 auto 100px; | ||
padding: 45px; | ||
text-align: center; | ||
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24); | ||
} | ||
.form input { | ||
outline: 0; | ||
background: #f2f2f2; | ||
width: 100%; | ||
border: 0; | ||
margin: 0 0 15px; | ||
padding: 15px; | ||
box-sizing: border-box; | ||
font-size: 14px; | ||
} | ||
.form button { | ||
text-transform: uppercase; | ||
outline: 0; | ||
background: #4CAF50; | ||
width: 100%; | ||
border: 0; | ||
padding: 15px; | ||
color: #FFFFFF; | ||
font-size: 14px; | ||
-webkit-transition: all 0.3 ease; | ||
transition: all 0.3 ease; | ||
cursor: pointer; | ||
} | ||
.form button:hover,.form button:active,.form button:focus { | ||
background: #43A047; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.img-thumbnail img{ | ||
width: 100%; | ||
} | ||
|
||
body{ | ||
font-family: 'Roboto Mono', monospace; | ||
} | ||
|
||
#logo{ | ||
font-size: 25px; | ||
} | ||
|
||
#nopads{ | ||
padding: 0; | ||
} | ||
|
||
#caption-padding{ | ||
padding: 5px; | ||
} | ||
|
||
#delete-button { | ||
display: inline; | ||
} | ||
|
||
.button-colour{ | ||
color: red; | ||
} | ||
|
||
#edit-button { | ||
display: inline; | ||
} | ||
|
||
#signedIn{ | ||
padding: 30px 60px 0 0; | ||
color: white; | ||
} | ||
|
||
|
||
/*These below were in style tag in header.ejs*/ | ||
.navbar { | ||
margin-bottom: 50px; | ||
} | ||
|
||
#inlineStyle { | ||
width: 30%; | ||
margin: 30px auto; | ||
} | ||
|
||
#header { | ||
text-align: center; | ||
} | ||
/*These above were in style tag in header.ejs*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
body { | ||
background-color: #000; | ||
} | ||
|
||
#landing-header { | ||
z-index: 1; | ||
position: relative; | ||
text-align: center; | ||
padding-top: 40vh; | ||
} | ||
|
||
#landing-header h1 { | ||
color: #fff; | ||
} | ||
|
||
.basic-font{ | ||
font-family: 'Roboto Mono', monospace; | ||
} | ||
|
||
.slideshow { | ||
position: fixed; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
z-index: 0; | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.slideshow li { | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
background-size: cover; | ||
background-position: 50% 50%; | ||
background-repeat: no-repeat; | ||
opacity: 0; | ||
z-index: 0; | ||
animation: imageAnimation 50s linear infinite; | ||
} | ||
|
||
.slideshow li:nth-child(1) { | ||
background-image: url(https://images.pexels.com/photos/211157/pexels-photo-211157.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940); | ||
} | ||
.slideshow li:nth-child(2) { | ||
background-image: url(https://images.pexels.com/photos/618848/pexels-photo-618848.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940); | ||
animation-delay: 10s; | ||
} | ||
.slideshow li:nth-child(3) { | ||
background-image: url(http://i.imgur.com/emvhOnb.jpg); | ||
animation-delay: 20s; | ||
} | ||
.slideshow li:nth-child(4) { | ||
background-image: url(https://images.pexels.com/photos/587976/pexels-photo-587976.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940); | ||
animation-delay: 30s; | ||
} | ||
.slideshow li:nth-child(5) { | ||
background-image: url(https://images.pexels.com/photos/93858/pexels-photo-93858.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940); | ||
animation-delay: 40s; | ||
} | ||
|
||
@keyframes imageAnimation { | ||
0% { | ||
opacity: 0; | ||
animation-timing-function: ease-in; | ||
} | ||
10% { | ||
opacity: 1; | ||
animation-timing-function: ease-out; | ||
} | ||
20% { | ||
opacity: 1 | ||
} | ||
30% { | ||
opacity: 0 | ||
} | ||
} | ||
|
||
/* Older browser support - .no-cssanimations class added by modernizr */ | ||
.no-cssanimations .slideshow li { | ||
opacity: 1; | ||
} | ||
|
||
|
Oops, something went wrong.