Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Sequelize = require('sequelize');
- var bcrypt = require('bcrypt');
- // create a sequelize instance with our local postgres database information.
- // var sequelize = new Sequelize('mysql://David@David:3307/IS');
- var sequelize = new Sequelize({
- host: 'data.velehradsky.cz',
- database: 'IS',
- port: 3307,
- username: 'David',
- password: 'David',
- dialect: 'mysql'
- });
- // setup User model and its fields.
- var User = sequelize.define('user_test', {
- UID: {
- type: Sequelize.INTEGER,
- unique: true,
- allowNull: false,
- autoIncrement: true,
- primaryKey: true
- },
- username: {
- type: Sequelize.STRING,
- unique: true,
- allowNull: false
- },
- email: {
- type: Sequelize.STRING,
- unique: true,
- allowNull: false
- },
- password: {
- type: Sequelize.STRING,
- allowNull: false
- }
- }, {
- freezeTableName: true,
- hooks: {
- beforeCreate: (user) => {
- const salt = bcrypt.genSaltSync();
- user.password = bcrypt.hashSync(user.password, salt);
- }
- },
- // instanceMethods: {
- // validPassword: function(password) {
- // return bcrypt.compareSync(password, this.password);
- // }
- // }
- });
- User.prototype.validPassword = function (password) {
- return bcrypt.compareSync(password, this.password);
- }
- // // create all the defined tables in the specified database.
- // sequelize.sync()
- // .then(() => console.log('users table has been successfully created, if one doesn\'t exist'))
- // .catch(error => console.log('This error occured', error));
- // export User model for use in other files.
- module.exports = User;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement