Skip to content

Commit

Permalink
Merge pull request #3 from zoaby/feature-branch
Browse files Browse the repository at this point in the history
backend authentication set-up
  • Loading branch information
z3by authored Apr 19, 2018
2 parents 4345bcc + e21803d commit f1056c5
Show file tree
Hide file tree
Showing 5 changed files with 615 additions and 7 deletions.
28 changes: 28 additions & 0 deletions db/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// requiring modules for mongoose
const mongoose = require('mongoose');
const db = mongoose.connection;
mongoose.connect('mongodb://localhost/Mine');

db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('connect');
});

const userSchema = mongoose.Schema({
userName: String,
passWord: String
});
const urlSchema = mongoose.Schema({
url: String,
category: String,
userName: String,
likes: Number,
comments: [String]
})
const Url = mongoose.model('Url', urlSchema)
const User = mongoose.model('User', userSchema);



module.exports.User = User;
module.exports.Url = Url;
18 changes: 18 additions & 0 deletions helpers/utility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
exports.createSession = (req, res, newUser) => {
return req.session.regenerate(() => {
req.session.user = newUser;
res.redirect('/');
});
}
exports.isLoggedIn = (req, res) => {
return req.session ? !!req.session.user : false;
};
exports.checkUser = (req, res, next) => {
if (!exports.isLoggedIn(req)) {
res.status(404)
res.redirect('/')
}
else {
next();
}
};
Loading

0 comments on commit f1056c5

Please sign in to comment.