Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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.
- }
Add Comment
Please, Sign In to add comment