-
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
Showing
58 changed files
with
1,057 additions
and
2,247 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
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
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,41 @@ | ||
const LocalStrategy = require("passport-local").Strategy; | ||
const mongoose = require("mongoose"); | ||
const bcrypt = require("bcryptjs"); | ||
|
||
// Load user model | ||
const User = mongoose.model("users"); | ||
|
||
module.exports = passport => { | ||
passport.use( | ||
new LocalStrategy( | ||
{ | ||
usernameField: "email" | ||
}, | ||
(email, password, done) => { | ||
User.findOne({ email }).then(user => { | ||
if (!user) { | ||
return done(null, false, { message: "No user found" }); | ||
} | ||
// Match Password | ||
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,10 @@ | ||
module.exports = { | ||
ensureAuthenticated: function(req, res, next) { | ||
if (req.isAuthenticated()) { | ||
return next(); | ||
} else { | ||
req.flash("error_msg", "Not authorized"); | ||
res.redirect("/users/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,24 @@ | ||
const moongose = require("mongoose"); | ||
const Schema = moongose.Schema; | ||
|
||
// Create Schema | ||
const IdeaSchema = new Schema({ | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
detail: { | ||
type: String, | ||
required: true | ||
}, | ||
userId: { | ||
type: String, | ||
required: true | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
moongose.model("ideas", IdeaSchema); |
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,24 @@ | ||
const moongose = require("mongoose"); | ||
const Schema = moongose.Schema; | ||
|
||
// Create Schema | ||
const UserSchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
email: { | ||
type: String, | ||
required: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
moongose.model("users", UserSchema); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.