Skip to content

refactor(model:user): exclude password info by default #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/templates/server/api/user(auth)/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ exports.changePassword = function(req, res, next) {
exports.me = function(req, res, next) {
var userId = req.user._id;

<% if (filters.mongooseModels) { %>User.findOneAsync({ _id: userId }, '-salt -hashedPassword')<% }
<% if (filters.mongooseModels) { %>User.findOneAsync({ _id: userId })<% }
if (filters.sequelizeModels) { %>User.find({
where: {
_id: userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ var UserSchema = new Schema({
type: String,
default: 'user'
},
password: String,
password: {type: String, select: false},
provider: String,
salt: String<% if (filters.oauth) { %>,<% if (filters.facebookAuth) { %>
salt: {type: String, select: false}<% if (filters.oauth) { %>,<% if (filters.facebookAuth) { %>
facebook: {},<% } %><% if (filters.twitterAuth) { %>
twitter: {},<% } %><% if (filters.googleAuth) { %>
google: {},<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ describe('User Model', function() {
return user.saveAsync();
});

it('should exclude salt and hashedPassword by default', function(done) {
User.find({name: user.name}, function(err, _user) {
_user.should.not.have.property('salt');
_user.should.not.have.property('hashedPassword');
done();
});
});

it('should authenticate user if valid', function() {
user.authenticate('password').should.be.true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ describe('User Model', function() {
return user.save();
});

it('should exclude salt and hashedPassword by default', function(done) {
User.find({name: user.name}, function(err, _user) {
_user.should.not.have.property('salt');
_user.should.not.have.property('hashedPassword');
done();
});
});

it('should authenticate user if valid', function() {
user.authenticate('password').should.be.true;
});
Expand Down
2 changes: 1 addition & 1 deletion app/templates/server/auth(auth)/local/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var LocalStrategy = require('passport-local').Strategy;
function localAuthenticate(User, email, password, done) {
<% if (filters.mongooseModels) { %>User.findOneAsync({
email: email.toLowerCase()
})<% }
}, '+salt +hashedPassword')<% }
if (filters.sequelizeModels) { %>User.find({
where: {
email: email.toLowerCase()
Expand Down