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
<!doctype html> | |
<html ng-app="app"> | |
<head> | |
<title>Node Authentication</title> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js"></script> | |
<script src="js/app.js"></script> |
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
<!doctype html> | |
<html> | |
<head> | |
<title>Node Authentication</title> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> | |
<style> | |
body { padding-top:80px; } | |
</style> | |
</head> |
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
// server.js | |
... | |
var session = require('express-session'); | |
var path = require('path'); // add path into our required list | |
... | |
app.use(passport.session()); // persistent login sessions | |
app.use(express.static(path.join(__dirname, '/public'))); //Expose /public | |
... |
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'), | |
mongoose = require('mongoose'), | |
User = mongoose.model('User'), | |
api = request(app); | |
describe('testing user authentication endpoints', function () { | |
// clear users out from the test database |
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
User.findOne({ 'local.email' : email }, function(err, user) { | |
// if there are any errors, return the error | |
if (err) | |
return done(err); | |
// check to see if theres already a user with that email | |
if (user) { | |
return done(null, { error: 'That email is already taken.' }); | |
} else { |
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'), | |
api = request(app); | |
describe('testing user authentication endpoints', function () { | |
it('successfully created a user', function (done) { | |
// make a post reqeust to the /signup route | |
api.post('/signup') | |
// send an email and password as part of the request body |
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'), | |
mongoose = require('mongoose'), | |
User = mongoose.model('User'), | |
api = request.agent(app); | |
describe('testing user authentication endpoints', function () { | |
// clear users out from the test database |
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
// app/routes.js | |
module.exports = function (app, passport) { | |
// LOGOUT ============================== | |
app.post('/logout', function(req, res) { | |
req.logout(); | |
res.json({ redirect: '/logout' }); | |
}); |
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
// app/models/user.js | |
// load the things we need | |
var mongoose = require('mongoose'); | |
var bcrypt = require('bcrypt-nodejs'); | |
// define the schema for our user model | |
var userSchema = mongoose.Schema({ | |
local : { | |
email : String, | |
password : String, |