Skip to content

Commit

Permalink
๐…๐ข๐ง๐š๐ฅ ๐•๐ž๐ซ๐ฌ๐ข๐จ๐ง ๐‹๐š๐ฎ๐ง๐œ๐ก
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish2030 committed Jul 2, 2021
1 parent 4a4fd97 commit ebe58b3
Show file tree
Hide file tree
Showing 391 changed files with 21,211 additions and 10,984 deletions.
Binary file added DS_Store.txt
Binary file not shown.
40 changes: 37 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ const seedDB = require('./seedDB');
const methodOverride = require('method-override')
const productRoutes = require('./routes/products/product');
const reviewRoutes = require('./routes/reviews/review');
const session = require('express-session');
const passport = require('passport');
const LocalStrategy = require('passport-local');
const User = require('./models/user');
const authRoutes = require('./routes/auth/auth');
const cartRoutes = require('./routes/cart/cart');



mongoose.connect('mongodb://localhost:27017/shopping-cart', { useNewUrlParser: true, useUnifiedTopology: true})
mongoose.connect('mongodb://localhost:27017/shopping-cart',
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex:true
})
.then(() => {
console.log("Database Connected");
})
Expand All @@ -24,22 +36,44 @@ app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/views'));
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
mongoose.set('useFindAndModify', false);
app.use(methodOverride('_method'))


//seedDB();
app.use(session({
secret: 'thisisnotagoodsecret',
resave: false,
saveUninitialized: true
}))


app.use(passport.initialize());
app.use(passport.session());


passport.use(new LocalStrategy(User.authenticate()));

passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

// seedDB();

app.get('/', (req, res) => {
res.render('landingPage');
})


app.use((req, res, next) => {
res.locals.currentUser = req.user;
next();
})

// Routes


app.use(productRoutes);
app.use(reviewRoutes);
app.use(authRoutes);
app.use(cartRoutes);



Expand Down
6 changes: 6 additions & 0 deletions imageStore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

FUTURE WORK

1.multer is used as middleware to upload images
2.Cloudinary
3.Add Flash functionality to display pop up msg (package : connect-flash)
8 changes: 8 additions & 0 deletions middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports.isLoggedIn = (req, res, next) => {

if (!req.isAuthenticated()) {
console.log("You must login first");
return res.redirect('/login');
}
next();
}
4 changes: 4 additions & 0 deletions models/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const reviewSchema = new mongoose.Schema({
body: {
type: String,
required:true
},
username: {
type: String,
required:true
}
})

Expand Down
22 changes: 22 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require('mongoose');
const passportLocalMongoose = require('passport-local-mongoose');
const Product = require('./product');

const userSchema = new mongoose.Schema({

email: {
type: String,
required: true,
unique: true,
},
cart: [
{
type: mongoose.Schema.Types.ObjectId,
ref:'Product'
}
]

});

userSchema.plugin(passportLocalMongoose);
module.exports = mongoose.model('User', userSchema);
4 changes: 2 additions & 2 deletions node_modules/@types/mongodb/README.md

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

Loading

0 comments on commit ebe58b3

Please sign in to comment.