Created
September 18, 2018 16:16
-
-
Save johann8384/f3893c89b82248b2da997f18ce9f8075 to your computer and use it in GitHub Desktop.
This file contains 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
// 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