SHARE
TWEET

Untitled

a guest Feb 4th, 2016 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env mode
  2.  
  3. var debug = require('debug')('entreeapp')
  4. var app = require('../server');
  5. var models = require('../model');
  6.  
  7. app.set('port', process.env.PORT || 3000);
  8.  
  9. //server running
  10. models.sequelize.sync({
  11.   force: true
  12. }).then(function () {
  13.   var server = app.listen(app.get('port'), function(){
  14.     debug('The magic is happening on port '+server.address().port);
  15.   });
  16. });
  17.    
  18. "use strict"
  19. var fs        = require('fs');
  20. var path      = require('path');
  21. var Sequelize = require('sequelize');
  22. var debug = require('debug');
  23. var env = process.env.NODE_ENV || "development";
  24. var config    = require(path.join(__dirname, '..', 'config', 'config.json'))[env];
  25. var db        = {};
  26. var sequelize = new Sequelize(config.database, config.username, config.password, config);
  27.  
  28.   sequelize.authenticate().then(function(){
  29.     debug('Database has been successfully authenticated');
  30.     return true;
  31.   }).catch(function(err){
  32.     debug('Failed to authenticate database: ', err);
  33.     return false;
  34.   });
  35.  
  36. fs.readdirSync(__dirname)
  37.   .filter(function(file) {
  38.     return (file.indexOf(".") !== 0) && (file !== 'index.js')
  39.   })
  40.   .forEach(function(file) {
  41.     var model = sequelize['import'](path.join(__dirname, file))
  42.     db[model.name] = model
  43.   });
  44.  
  45.  
  46. db.sequelize = sequelize;
  47. db.Sequelize = Sequelize;
  48.  
  49. module.exports = db;
  50.    
  51. module.exports = function(sequelize, DataType){
  52.  
  53.   var User = sequelize.define('user', {
  54.     name: DataType.STRING,
  55.     password: DataType.STRING,
  56.     lastName: DataType.STRING,
  57.     email: DataType.STRING,
  58.     gender: DataType.CHAR,
  59.     cellNumber: DataType.INTEGER
  60.   }, {
  61.     instanceMethods : {
  62.       create : function(onSuccess, onError){
  63.         var name = this.name;
  64.         var lastName = this.lastName;
  65.         var email = this.email;
  66.         var gender = this.gender;
  67.         var cellNumber = this.cellNumber;
  68.         var password = this.password;
  69.  
  70.         var shasum = crypto.createHash('sha1');
  71.         shasum.update(password);
  72.         password = shasum.digest('hex');
  73.  
  74.         User.build({name: name, lastName: lastName, email: email, gender: gender, cellNumber: cellNumber, password: password})
  75.           .save().success(onSuccess).error(onError);
  76.       }
  77.     }
  78.   });
  79.  
  80.   return User;
  81. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top