Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created March 14, 2014 15:12
Show Gist options
  • Save tanepiper/9549621 to your computer and use it in GitHub Desktop.
Save tanepiper/9549621 to your computer and use it in GitHub Desktop.
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);
});
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