forked from jedireza/drywall
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* migrated most of the models * migrated signup code to use sequelize * migrated passport login code to use sequelize
- Loading branch information
Showing
17 changed files
with
919 additions
and
537 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.js] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.jsx] | ||
e4x = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.hbs] | ||
insert_final_newline = false | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.css] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.html] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.{diff,md}] | ||
trim_trailing_whitespace = false |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"development": { | ||
"username": "ieugen", | ||
"password": "parola", | ||
"database": "push-my-users", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres", | ||
"logger": "console.log" | ||
}, | ||
"production": { | ||
"username": "uagackoj", | ||
"password": "8VMbOEcEeYXhprgMSmLQr0dkma8KK4Xo", | ||
"database": "uagackoj", | ||
"host": "qdjjtnkv.db.elephantsql.com", | ||
"dialect": "postgres" | ||
}, | ||
"twitter": { | ||
"consumerKey": "YVvczcYv0x4d4UPmgTcpK40qE", | ||
"consumerSecret": "SrTH2YWf2LS2pQiMoIpvt2n5MtneDf6l8A0aHTKooTvXyN6jPf" | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* jshint indent: 2 */ | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('Account', { | ||
isVerified: { | ||
type: DataTypes.STRING | ||
}, | ||
name: { | ||
type: DataTypes.JSON | ||
}, | ||
company: { | ||
type: DataTypes.STRING | ||
}, | ||
phone: { | ||
type: DataTypes.STRING | ||
}, | ||
zip: { | ||
type: DataTypes.STRING | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('Admin', { | ||
name: { | ||
type: DataTypes.JSON | ||
}, | ||
name: { | ||
type: DataTypes.JSON | ||
}, | ||
}, { | ||
freezeTableName: true, | ||
instanceMethods: { | ||
hasPermissionTo: function(something) { | ||
//check group permissions | ||
var groupHasPermission = false; | ||
for (var i = 0; i < this.groups.length; i++) { | ||
for (var j = 0; j < this.groups[i].permissions.length; j++) { | ||
if (this.groups[i].permissions[j].name === something) { | ||
if (this.groups[i].permissions[j].permit) { | ||
groupHasPermission = true; | ||
} | ||
} | ||
} | ||
} | ||
//check admin permissions | ||
for (var k = 0; k < this.permissions.length; k++) { | ||
if (this.permissions[k].name === something) { | ||
if (this.permissions[k].permit) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
return groupHasPermission; | ||
}, | ||
isMemberOf: function(group) { | ||
for (var i = 0; i < this.groups.length; i++) { | ||
if (this.groups[i]._id === group) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
}) | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('AdminGroup', { | ||
name: { | ||
type: DataTypes.STRING | ||
}, | ||
permissions: { | ||
type: DataTypes.JSON | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('Category', { | ||
name: { | ||
type: DataTypes.STRING | ||
}, | ||
pivot: { | ||
type: DataTypes.STRING | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('LoginAttempt', { | ||
ip: { | ||
type: DataTypes.STRING | ||
}, | ||
user: { | ||
type: DataTypes.STRING | ||
}, | ||
time: { | ||
type: DataTypes.DATE, | ||
defaultValue: DataTypes.NOW | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* jshint indent: 2 */ | ||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('Message', { | ||
name: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
}, | ||
body: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('Note', { | ||
data: { | ||
type: DataTypes.STRING | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('Status', { | ||
name: { | ||
type: DataTypes.STRING | ||
}, | ||
pivot: { | ||
type: DataTypes.STRING | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('StatusLog', { | ||
name: { | ||
type: DataTypes.STRING | ||
} | ||
}, { | ||
freezeTableName: true | ||
}); | ||
}; | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* jshint indent: 2 */ | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('User', { | ||
username: { | ||
type: DataTypes.STRING, | ||
unique: true, | ||
allowNull: false | ||
}, | ||
password: DataTypes.STRING, | ||
email: { | ||
type: DataTypes.STRING, | ||
unique: true | ||
}, | ||
isActive: DataTypes.STRING, | ||
resetPasswordToken: DataTypes.STRING, | ||
resetPasswordExpires: DataTypes.DATE, | ||
twitter: DataTypes.JSON, | ||
github: DataTypes.JSON, | ||
facebook: DataTypes.JSON, | ||
google: DataTypes.JSON, | ||
tumblr: DataTypes.JSON | ||
}, { | ||
freezeTableName: true, | ||
instanceMethods: { | ||
canPlayRoleOf: function(role) { | ||
return false; | ||
}, | ||
defaultReturnUrl: function() { | ||
var returnUrl = '/'; | ||
if (this.canPlayRoleOf('account')) { | ||
returnUrl = '/account/'; | ||
} | ||
|
||
if (this.canPlayRoleOf('admin')) { | ||
returnUrl = '/admin/'; | ||
} | ||
|
||
return returnUrl; | ||
} | ||
}, | ||
classMethods: { | ||
encryptPassword: function(password, done) { | ||
var bcrypt = require('bcrypt'); | ||
bcrypt.genSalt(10, function(err, salt) { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
bcrypt.hash(password, salt, function(err, hash) { | ||
done(err, hash); | ||
}); | ||
}); | ||
}, | ||
validatePassword: function(password, hash, done) { | ||
var bcrypt = require('bcrypt'); | ||
bcrypt.compare(password, hash, function(err, res) { | ||
done(err, res); | ||
}); | ||
} | ||
|
||
} | ||
}); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"use strict"; | ||
|
||
let fs = require("fs"); | ||
let path = require("path"); | ||
let Sequelize = require("sequelize"); | ||
let basename = path.basename(module.filename); | ||
let env = process.env.NODE_ENV || "development"; | ||
let config = require(__dirname + '/../config/config.json')[env]; | ||
let sequelize = new Sequelize(config.database, config.username, config.password, config); | ||
let db = {}; | ||
|
||
console.log('Drywall aaa'); | ||
|
||
fs | ||
.readdirSync(__dirname) | ||
.filter(function(file) { | ||
return (file.indexOf(".") !== 0) && (file !== basename); | ||
}) | ||
.forEach(function(file) { | ||
let model = sequelize["import"](path.join(__dirname, file)); | ||
db[model.name] = model; | ||
}); | ||
|
||
Object.keys(db).forEach(function(modelName) { | ||
if ("associate" in db[modelName]) { | ||
db[modelName].associate(db); | ||
} | ||
}); | ||
|
||
let options = { | ||
force: true | ||
} | ||
|
||
db.sequelize = sequelize; | ||
db.Sequelize = Sequelize; | ||
|
||
db.User.sync(options).then(function() { | ||
|
||
db.Message.belongsTo(db.User); | ||
db.Account.belongsTo(db.User); | ||
|
||
db.Account.sync(options); | ||
db.Message.sync(options); | ||
|
||
db.Admin.sync(options); | ||
db.AdminGroup.sync(options); | ||
db.Category.sync(options); | ||
db.LoginAttempt.sync(options); | ||
db.Note.sync(options); | ||
db.Status.sync(options); | ||
db.StatusLog.sync(options); | ||
|
||
}); | ||
|
||
|
||
module.exports = db; | ||
|
Oops, something went wrong.