-
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
0 parents
commit 8ed2211
Showing
41 changed files
with
3,819 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,2 @@ | ||
node_modules | ||
.env |
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,50 @@ | ||
const express = require('express'); | ||
const expressLayouts = require('express-ejs-layouts'); | ||
const mongoose = require('mongoose'); | ||
const flash = require('connect-flash'); | ||
const session = require('express-session'); | ||
const passport = require('passport'); | ||
|
||
require('dotenv').config() | ||
require('./config/passport')(passport); | ||
|
||
|
||
const app = express(); | ||
|
||
const db = require('./config/keys').MongoURI; | ||
|
||
mongoose.connect(db, { useUnifiedTopology: true, useNewUrlParser: true }) | ||
.then(() => console.log('MongoDB Connected...')) | ||
.catch(err => console.log(err)) | ||
|
||
app.use(expressLayouts); | ||
app.set('view engine', 'ejs'); | ||
|
||
app.use(express.urlencoded({ extended: false })); | ||
|
||
app.use( | ||
session({ | ||
secret: 'secret', | ||
resave: true, | ||
saveUninitialized: true | ||
}) | ||
); | ||
|
||
app.use(passport.initialize()); | ||
app.use(passport.session()); | ||
|
||
app.use(flash()); | ||
|
||
app.use((req, res, next) => { | ||
res.locals.success_msg = req.flash('success_msg'); | ||
res.locals.error_msg = req.flash('error_msg'); | ||
res.locals.error = req.flash('error'); | ||
next(); | ||
}) | ||
|
||
app.use('/', require('./routes/index')) | ||
app.use(express.static('public')); | ||
|
||
const PORT = process.env.PORT || 8000; | ||
|
||
app.listen(PORT, console.log(`Server started on port ${PORT}`)); |
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,9 @@ | ||
module.exports = { | ||
ensureAuthenticated: function(req, res, next) { | ||
if(req.isAuthenticated()) { | ||
return next(); | ||
} | ||
req.flash('error_msg', 'Please log in to view the page'); | ||
res.redirect('/login'); | ||
} | ||
} |
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,3 @@ | ||
module.exports = { | ||
MongoURI: process.env.DB_URL | ||
} |
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,39 @@ | ||
const LocalStrategy = require('passport-local').Strategy; | ||
const bcrypt = require('bcryptjs'); | ||
|
||
const User = require('../models/User'); | ||
|
||
module.exports = function(passport) { | ||
passport.use( | ||
new LocalStrategy({ usernameField: 'username' }, (username, password, done) => { | ||
User.findOne({ | ||
username: username | ||
}).then(user => { | ||
if (!user) { | ||
return done(null, false, { message: 'That username is not registered' }); | ||
} | ||
if (user.status == 'unverified') { | ||
return done(null, false, { message: 'Your email is not verified' }); | ||
} | ||
bcrypt.compare(password, user.password, (err, isMatch) => { | ||
if (err) throw err; | ||
if (isMatch) { | ||
return done(null, user); | ||
} else { | ||
return done(null, false, { message: 'Password incorrect' }); | ||
} | ||
}); | ||
}); | ||
}) | ||
); | ||
|
||
passport.serializeUser(function(user, done) { | ||
done(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser(function(id, done) { | ||
User.findById(id, function(err, user) { | ||
done(err, user); | ||
}); | ||
}); | ||
}; |
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,57 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const PostSchema = new mongoose.Schema({ | ||
username: { | ||
type: String, | ||
required: true | ||
}, | ||
user_age: { | ||
type: Number, | ||
required: false | ||
}, | ||
field_experience: { | ||
type: Number, | ||
required: false | ||
}, | ||
portfolio_link: { | ||
type: String, | ||
required: true | ||
}, | ||
message: { | ||
type: String, | ||
required: true | ||
}, | ||
category: { | ||
type: String, | ||
required: true | ||
}, | ||
reviewers: { | ||
type: Number, | ||
required: false | ||
}, | ||
value: { | ||
type: Number, | ||
required: false, | ||
default: 0 | ||
}, | ||
level: { | ||
type: String, | ||
required: false | ||
}, | ||
reviewers_usernames: { | ||
type: Array, | ||
required: false | ||
}, | ||
reviews: { | ||
type: Array, | ||
required: false | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
}, | ||
}) | ||
|
||
const Post = mongoose.model('Post', PostSchema); | ||
|
||
module.exports = Post; |
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,53 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const UserSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
age: { | ||
type: Number, | ||
required: true | ||
}, | ||
gender: { | ||
type: String, | ||
required: true | ||
}, | ||
username: { | ||
type: String, | ||
required: true | ||
}, | ||
email: { | ||
type: String, | ||
required: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true | ||
}, | ||
status: { | ||
type: String, | ||
required: true | ||
}, | ||
code: { | ||
type: String, | ||
required: false | ||
}, | ||
categories: { | ||
type: Array, | ||
required: false | ||
}, | ||
reviews_done: { | ||
type: Number, | ||
required: false, | ||
default: 0 | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
}, | ||
}) | ||
|
||
const User = mongoose.model('User', UserSchema); | ||
|
||
module.exports = User; |
Oops, something went wrong.