Skip to content

Commit 5fecaba

Browse files
committed
refactor(model:user): exclude password info by default
thanks to guiltry for the original commit (89980c5)
1 parent 2a1f37a commit 5fecaba

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

Diff for: app/templates/server/api/user(auth)/user.controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ exports.changePassword = function(req, res, next) {
143143
exports.me = function(req, res, next) {
144144
var userId = req.user._id;
145145

146-
<% if (filters.mongooseModels) { %>User.findOneAsync({ _id: userId }, '-salt -hashedPassword')<% }
146+
<% if (filters.mongooseModels) { %>User.findOneAsync({ _id: userId })<% }
147147
if (filters.sequelizeModels) { %>User.find({
148148
where: {
149149
_id: userId

Diff for: app/templates/server/api/user(auth)/user.model(mongooseModels).js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ var UserSchema = new Schema({
1515
type: String,
1616
default: 'user'
1717
},
18-
password: String,
18+
password: {type: String, select: false},
1919
provider: String,
20-
salt: String<% if (filters.oauth) { %>,<% if (filters.facebookAuth) { %>
20+
salt: {type: String, select: false}<% if (filters.oauth) { %>,<% if (filters.facebookAuth) { %>
2121
facebook: {},<% } %><% if (filters.twitterAuth) { %>
2222
twitter: {},<% } %><% if (filters.googleAuth) { %>
2323
google: {},<% } %>

Diff for: app/templates/server/api/user(auth)/user.model.spec(mongooseModels).js

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ describe('User Model', function() {
5252
return user.saveAsync();
5353
});
5454

55+
it('should exclude salt and hashedPassword by default', function(done) {
56+
User.find({name: user.name}, function(err, _user) {
57+
_user.should.not.have.property('salt');
58+
_user.should.not.have.property('hashedPassword');
59+
done();
60+
});
61+
});
62+
5563
it('should authenticate user if valid', function() {
5664
user.authenticate('password').should.be.true;
5765
});

Diff for: app/templates/server/api/user(auth)/user.model.spec(sequelizeModels).js

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ describe('User Model', function() {
5454
return user.save();
5555
});
5656

57+
it('should exclude salt and hashedPassword by default', function(done) {
58+
User.find({name: user.name}, function(err, _user) {
59+
_user.should.not.have.property('salt');
60+
_user.should.not.have.property('hashedPassword');
61+
done();
62+
});
63+
});
64+
5765
it('should authenticate user if valid', function() {
5866
user.authenticate('password').should.be.true;
5967
});

Diff for: app/templates/server/auth(auth)/local/passport.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var LocalStrategy = require('passport-local').Strategy;
44
function localAuthenticate(User, email, password, done) {
55
<% if (filters.mongooseModels) { %>User.findOneAsync({
66
email: email.toLowerCase()
7-
})<% }
7+
}, '+salt +hashedPassword')<% }
88
if (filters.sequelizeModels) { %>User.find({
99
where: {
1010
email: email.toLowerCase()

0 commit comments

Comments
 (0)