Created
March 14, 2014 15:12
-
-
Save tanepiper/9549621 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Instance.db.User.find({ | |
where: {email: username}, | |
attributes: ['id', 'email'] | |
}) | |
.success(function(user) { | |
if (!user) { | |
return done(null, false, Instance.error.notFound('User not found')); | |
} else if (!user.checkPassword(password)) { | |
return done(null, false, Instance.error.unauthorized('Password incorrect')); | |
} else { | |
done(null, user); | |
} | |
}) | |
.error(function(err) { | |
console.log(err); | |
done(err); | |
}); |
This file contains hidden or 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
Instance.db.User = Instance.db.sequelize.define('user', { | |
email: { | |
type: Sequelize.STRING, | |
allowNull: false, | |
validate: { | |
isEmail: true | |
} | |
}, | |
password: { | |
type: Sequelize.STRING, | |
allowNull: false | |
} | |
}, { | |
classMethods: { | |
}, | |
instanceMethods: { | |
hashPassword: function(password) { | |
this.password = Bcrypt.hashSync(this.password, 10); | |
return this; | |
}, | |
checkPassword: function(password) { | |
return Bcrypt.compareSync(password, this.password); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment