Skip to content

Instantly share code, notes, and snippets.

@johann8384
Created September 18, 2018 16:16
Show Gist options
  • Save johann8384/f3893c89b82248b2da997f18ce9f8075 to your computer and use it in GitHub Desktop.
Save johann8384/f3893c89b82248b2da997f18ce9f8075 to your computer and use it in GitHub Desktop.
// 1: The model schema.
var modelDefinition = {
username: {
type: Sequelize.STRING,
unique: true,
allowNull: false
},
password: {
type: Sequelize.STRING,
allowNull: false
}
};
// 2: The model options.
var modelOptions = {
instanceMethods: {
comparePasswords: comparePasswords
},
hooks: {
beforeValidate: hashPassword
}
};
// 3: Define the User model.
var UserModel = db.define('user', modelDefinition, modelOptions);
// Compares two passwords. Will be available on an instance when retrieved.
function comparePasswords(password, callback) {
// TODO: Password comparison logic.
}
// Hashes the password for a user object. Handled before the INSERT
function hashPassword(user) {
// TODO: Password hashing logic.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment