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
var app = require('../../server.js'), | |
should = require('should'), | |
request = require('supertest'), | |
User = require('../../app/models/user.js'), | |
api = request(app); | |
describe('testing user authentication endpoints', function () { | |
beforeEach(function (done) { | |
User.remove({}, function() { | |
done(); |
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
{ | |
"name": "tdd-mocha-express-passport", | |
"version": "0.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"test": "mocha tests/server" | |
}, | |
"author": "", | |
"license": "ISC", |
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
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; | |
var mongoose = require('./config/mongoose'), | |
express = require('./config/express'); | |
var db = mongoose(); | |
var app = express(); | |
app.listen(3000); |
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
var mongoose = require('mongoose'); | |
module.exports = function() { | |
var db = mongoose.connect('mongodb://localhost:2701/passporttdd'); | |
return db; | |
}; |
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
var express = require('express'), | |
morgan = require('morgan'), | |
compress = require('compression'), | |
bodyParser = require('body-parser'), | |
methodOverride = require('method-override'), | |
session = require('express-session'), | |
passport = require('passport'); | |
module.exports = function() { |
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
var LocalStrategy = require('passport-local').Strategy; | |
var User = require('../app/models/user'); | |
module.exports = function (passport) { | |
passport.serializeUser(function (user, done) { | |
done(null, user.id); | |
}); | |
passport.deserializeUser(function (id, done) { | |
User.findById(id, function (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
var mongoose = require('mongoose'); | |
var userSchema = mongoose.Schema({ | |
username: { | |
type: String, | |
required: true, | |
index: {unique: true} | |
}, | |
password: { | |
type: String, |
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
module.exports = function(app, passport) { | |
app.route('/register') | |
.post(function(req, res, next) { | |
if (!req.body.username || !req.body.password) { | |
return res.status(400).json({error: 'Username and Password required'}); | |
} | |
passport.authenticate('local-signup', function(err, user, info) { | |
if (err) { |
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
{ | |
"name": "authentication-set-up-and-testing", | |
"main": "server.js", | |
"dependencies" : { | |
"express" : "~4.8.8", | |
"mongoose" : "~3.8.1", | |
"passport" : "~0.1.17", | |
"passport-local": "~1.0.0", | |
"bcrypt-nodejs" : "latest", | |
"morgan": "~1.3.0", |
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
// get all the tools we need | |
var express = require('express'); | |
var app = express(); | |
var port = process.env.PORT || 8080; | |
var mongoose = require('mongoose'); | |
var passport = require('passport'); | |
var morgan = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); |
OlderNewer