Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/pontifier/mean into pontifi…
Browse files Browse the repository at this point in the history
…er-master

Conflicts:
	gruntfile.js
	package.json
  • Loading branch information
amoshaviv committed Oct 23, 2013
2 parents 3e757fd + 71365db commit 6dbe996
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 27 deletions.
22 changes: 7 additions & 15 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
crypto = require('crypto'),
scrypt = require('scrypt'),
_ = require('underscore'),
authTypes = ['github', 'twitter', 'facebook', 'google'];

Expand All @@ -14,10 +15,9 @@ var mongoose = require('mongoose'),
var UserSchema = new Schema({
name: String,
email: String,
username: String,
username: {type: String, unique: true},
provider: String,
hashed_password: String,
salt: String,
facebook: {},
twitter: {},
github: {},
Expand All @@ -29,7 +29,6 @@ var UserSchema = new Schema({
*/
UserSchema.virtual('password').set(function(password) {
this._password = password;
this.salt = this.makeSalt();
this.hashed_password = this.encryptPassword(password);
}).get(function() {
return this._password;
Expand Down Expand Up @@ -92,18 +91,9 @@ UserSchema.methods = {
* @api public
*/
authenticate: function(plainText) {
return this.encryptPassword(plainText) === this.hashed_password;
return scrypt.verifyHashSync(this.hashed_password, plainText);
},

/**
* Make salt
*
* @return {String}
* @api public
*/
makeSalt: function() {
return Math.round((new Date().valueOf() * Math.random())) + '';
},

/**
* Encrypt password
Expand All @@ -114,8 +104,10 @@ UserSchema.methods = {
*/
encryptPassword: function(password) {
if (!password) return '';
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
var maxtime = 0.1;
return scrypt.passwordHashSync(password, maxtime);
//return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
}
};

mongoose.model('User', UserSchema);
mongoose.model('User', UserSchema);
8 changes: 4 additions & 4 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var express = require('express'),
helpers = require('view-helpers'),
config = require('./config');

module.exports = function(app, passport) {
module.exports = function(app, passport, db) {
app.set('showStackError', true);

app.locals.pretty = true;
//Should be placed before express.static
app.use(express.compress({
filter: function(req, res) {
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = function(app, passport) {
app.use(express.session({
secret: 'MEAN',
store: new mongoStore({
url: config.db,
db: db.connection.db,
collection: 'sessions'
})
}));
Expand Down Expand Up @@ -87,4 +87,4 @@ module.exports = function(app, passport) {
});

});
};
};
14 changes: 12 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ module.exports = function(grunt) {
options: {
livereload: true
}
}
},
test: {
files: '*',
tasks: ['test']
}
},
jshint: {
all: ['gruntfile.js', 'public/js/**/*.js', 'test/**/*.js', 'app/**/*.js']
Expand Down Expand Up @@ -60,6 +64,11 @@ module.exports = function(grunt) {
reporter: 'spec'
},
src: ['test/**/*.js']
},
env: {
test: {
NODE_ENV: 'test'
}
}
});

Expand All @@ -69,6 +78,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-env');

//Making grunt default to force in order not to break the project.
grunt.option('force', true);
Expand All @@ -77,5 +87,5 @@ module.exports = function(grunt) {
grunt.registerTask('default', ['jshint', 'concurrent']);

//Test task.
grunt.registerTask('test', ['mochaTest']);
grunt.registerTask('test', ['env:test', 'mochaTest']);
};
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@
"forever": "latest",
"bower": "latest",
"grunt": "latest",
<<<<<<< HEAD
"grunt-cli": "latest"
=======
"grunt-cli": "latest",
"grunt-env": "latest",
"grunt-bower-task": "latest",
"scrypt": "latest"
>>>>>>> 71365db8398cfc2c1d40aceef4cb25927109eb10
},
"devDependencies": {
"supertest": "latest",
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require('./config/passport')(passport);
var app = express();

//express settings
require('./config/express')(app, passport);
require('./config/express')(app, passport, db);

//Bootstrap routes
require('./config/routes')(app, passport, auth);
Expand Down
9 changes: 8 additions & 1 deletion test/article/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ describe('<Unit Test>', function() {
});

afterEach(function(done) {
Article.remove({});
User.remove({});
done();
});
after(function(done){
Article.remove().exec();
User.remove().exec();
done();
});
});
});
});
27 changes: 23 additions & 4 deletions test/user/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@ describe('<Unit Test>', function() {
username: 'user',
password: 'password'
});
user2 = new User({
name: 'Full name',
email: 'test@test.com',
username: 'user',
password: 'password'
});

done();
});

describe('Method Save', function() {
it('should begin with no users', function(done){
User.find({}, function(err,users){
users.should.have.length(0);
done();
});
});

it('should be able to save whithout problems', function(done) {
return user.save(function(err) {
should.not.exist(err);
done();
user.save(done);
});

it('should fail to save an existing user again', function(done) {
user.save();
return user2.save(function(err){
should.exist(err);
done();
});
});

Expand All @@ -41,7 +59,8 @@ describe('<Unit Test>', function() {
});

after(function(done) {
User.remove().exec();
done();
});
});
});
});

0 comments on commit 6dbe996

Please sign in to comment.