Skip to content

Commit 8a6fffc

Browse files
Merge pull request #232 from CloudBoost/staging
Staging
2 parents e517f38 + e031322 commit 8a6fffc

File tree

6 files changed

+121
-7
lines changed

6 files changed

+121
-7
lines changed

api/tables/CloudObjects.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
var customHelper = require('../../helpers/custom.js');
8-
8+
var integrationService = require('../../services/integrationService')();
99
module.exports = function() {
1010

1111
global.app.put('/data/:appId/:tableName', function(req, res) { //save a new document into <tableName> of app
@@ -27,6 +27,9 @@ module.exports = function() {
2727
}).then(function(result) {
2828
console.log('+++ Save Success +++');
2929
console.log(result);
30+
if (collectionName == "_Event") {
31+
integrationService.integrationNotification(appId, document);
32+
}
3033
res.status(200).send(result);
3134
}, function(error) {
3235
console.log('++++++ Save Error +++++++');

api/tables/CloudUser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = function() {
6969

7070
var isMasterKey = false;
7171
var sessionLength = 30; //Default
72-
72+
7373
var promises = [];
7474
promises.push(global.appService.getAllSettings(appId));
7575
promises.push(global.appService.isMasterKey(appId, appKey));

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"q": "^2.0.3",
5858
"request": "^2.55.0",
5959
"should": "^4.6.5",
60+
"slack-node": "^0.1.8",
6061
"socket.io": "^1.4.5",
6162
"socket.io-redis": "^0.1.4",
6263
"underscore": "^1.7.0",

services/cloudObjects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ function _modifyFieldsInQuery(appId, collectionName, query) {
13531353

13541354
function _encrypt(data) {
13551355
try {
1356-
return crypto.pbkdf2Sync(data, global.keys.secureKey, 10000, 64).toString('base64');
1356+
return crypto.pbkdf2Sync(data, global.keys.secureKey, 10000, 64, 'sha512').toString('base64');
13571357
} catch (err) {
13581358
global.winston.log('error', {
13591359
"error": String(err),

services/cloudUser.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = function() {
2929
}
3030

3131
var isAuthenticatedUser=false;
32-
var encryptedPassword = crypto.pbkdf2Sync(password, global.keys.secureKey, 10000, 64).toString('base64');
32+
var encryptedPassword = crypto.pbkdf2Sync(password, global.keys.secureKey, 10000, 64, 'sha512').toString('base64');
3333
if (encryptedPassword === user.password) { //authenticate user.
3434
isAuthenticatedUser=true;
3535
}
@@ -90,9 +90,9 @@ module.exports = function() {
9090
return;
9191
}
9292

93-
var encryptedPassword = crypto.pbkdf2Sync(oldPassword, global.keys.secureKey, 10000, 64).toString('base64');
93+
var encryptedPassword = crypto.pbkdf2Sync(oldPassword, global.keys.secureKey, 10000, 64, 'sha512').toString('base64');
9494
if (encryptedPassword === user.password) { //authenticate user.
95-
user.password = crypto.pbkdf2Sync(newPassword, global.keys.secureKey, 10000, 64).toString('base64');
95+
user.password = crypto.pbkdf2Sync(newPassword, global.keys.secureKey, 10000, 64, 'sha512').toString('base64');
9696
global.mongoService.document.save(appId, [{document:user}]).then(function(document) {
9797
deferred.resolve(user); //returns no. of items matched
9898
}, function(error) {
@@ -173,7 +173,7 @@ module.exports = function() {
173173
.digest('hex');
174174

175175
if(passwordResetKey === resetKey){
176-
user.password = crypto.pbkdf2Sync(newPassword, global.keys.secureKey, 10000, 64).toString('base64');
176+
user.password = crypto.pbkdf2Sync(newPassword, global.keys.secureKey, 10000, 64, 'sha512').toString('base64');
177177
global.mongoService.document.save(appId, [{document:user}]).then(function(user) {
178178
deferred.resolve(); //returns no. of items matched
179179
}, function(error) {

services/integrationService.js

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
var Slack = require('slack-node');
2+
3+
module.exports = function () {
4+
5+
6+
return {
7+
integrationNotification: function (appId, document) {
8+
var integration_api = ["slack"];
9+
global.appService.getApp(appId).then(function (application) {
10+
var appName = application.name;
11+
global.appService.getAllSettings(appId).then(function (settings) {
12+
var integrationSettings;
13+
settings.forEach(function (element) {
14+
if (element.category == "integrations") {
15+
integrationSettings = element.settings;
16+
}
17+
}, this);
18+
if (integrationSettings) {
19+
for (var i = 0; i < integration_api.length; i++) {
20+
switch (integration_api[i]) {
21+
case "slack":
22+
if (integrationSettings.slack.enabled) {
23+
notifyOnSlack(integrationSettings.slack, document, appName);
24+
}
25+
break;
26+
}
27+
}
28+
}
29+
30+
});
31+
});
32+
}
33+
}
34+
35+
}
36+
37+
function notifyOnSlack(integrationSettings, document, appName) {
38+
var slack = new Slack();
39+
var timeStamp = Math.floor(Date.now() / 1000);
40+
41+
//req data
42+
var event_type = document.name;
43+
var user = document.data.username;
44+
var user_email = document.data.email;
45+
46+
slack.setWebhook(integrationSettings.webhook_url);
47+
var text, image, title, color;
48+
switch (event_type) {
49+
case "Login":
50+
if (integrationSettings.loginNotify === true) {
51+
title = "Login";
52+
text = "A user just logged in to " + appName + " application"
53+
color = "#36a64f"
54+
}
55+
break;
56+
case "Signup":
57+
if (integrationSettings.signUpNotify === true) {
58+
title = "Sign Up";
59+
text = "A new user just signed up for your " + appName + " application"
60+
color = "#5CACEE";
61+
}
62+
break;
63+
default:
64+
title = event_type;
65+
color = "#9932CC";
66+
}
67+
if (title) {
68+
slack.webhook({
69+
channel: "#general",
70+
username: "CloudBoost",
71+
attachments: [
72+
{
73+
"fallback": "Whenever a User Triggers any event a notification will appear here",
74+
"color": color,
75+
"pretext": text,
76+
"author_name": "Event Notifications",
77+
"author_link": "https://www.cloudboost.io/",
78+
"author_icon": "https://d1qb2nb5cznatu.cloudfront.net/startups/i/490103-917cc2864d0246e313e9521971422f09-medium_jpg.jpg?buster=1430997518",
79+
"title": "User " + event_type + " Notification",
80+
"title_link": "https://www.cloudboost.io/",
81+
// "text": text,
82+
"fields": [
83+
{
84+
"title": "User Name",
85+
"value": user,
86+
"short": false
87+
},
88+
{
89+
"title": "User Email",
90+
"value": user_email,
91+
"short": false
92+
}
93+
],
94+
"footer": "CloudBoost",
95+
"footer_icon": "https://d1qb2nb5cznatu.cloudfront.net/startups/i/490103-917cc2864d0246e313e9521971422f09-medium_jpg.jpg?buster=1430997518",
96+
"ts": timeStamp
97+
}
98+
],
99+
icon_emoji: "https://d1qb2nb5cznatu.cloudfront.net/startups/i/490103-917cc2864d0246e313e9521971422f09-medium_jpg.jpg?buster=1430997518"
100+
}, function (err, response) {
101+
if (!err) {
102+
console.log(response);
103+
} else {
104+
console.log(err);
105+
}
106+
});
107+
return true;
108+
}
109+
return false;
110+
}

0 commit comments

Comments
 (0)