Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
6faf4f2
Added landing
jbull328 Jan 21, 2017
7816b24
Added landing
jbull328 Jan 21, 2017
8cef0a2
Added oganization signup page
jbull328 Jan 21, 2017
f25888a
Added oganization signup route
jbull328 Jan 21, 2017
9874e80
Added oganization signup route
jbull328 Jan 21, 2017
9c634ea
Added oganization signup route
jbull328 Jan 21, 2017
9c53058
Added login route to login button
jbull328 Jan 21, 2017
d7fc06e
Added login route to login button
jbull328 Jan 21, 2017
bdbbe84
Added login route to sign up page button
jbull328 Jan 21, 2017
551884b
Added login route to sign up page button
jbull328 Jan 21, 2017
3bf99d9
Added login required to newOrganization
jbull328 Jan 21, 2017
eaca7f5
Added oganization signup page
jbull328 Jan 21, 2017
081a2d8
Added oganization signup route
jbull328 Jan 21, 2017
ac2ff17
Added oganization signup route
jbull328 Jan 21, 2017
81557a6
Added oganization signup route
jbull328 Jan 21, 2017
2ec9a41
Added login route to login button
jbull328 Jan 21, 2017
96f4242
Added login route to login button
jbull328 Jan 21, 2017
dcd2d7c
Added login route to sign up page button
jbull328 Jan 21, 2017
7d07f43
Added login route to sign up page button
jbull328 Jan 21, 2017
d2fb28f
Added login required to newOrganization
jbull328 Jan 21, 2017
905b695
Merge branch 'master' of https://github.com/jbull328/ValleyHack
jbull328 Jan 21, 2017
3400636
added post route to new org
jbull328 Jan 21, 2017
300de4f
added post route to new org
jbull328 Jan 21, 2017
30a3590
typo
jbull328 Jan 21, 2017
9c49b86
added action and method to new Org
jbull328 Jan 21, 2017
50f5da6
added action and method to new Org
jbull328 Jan 21, 2017
72bf19b
added action and method to new Org
jbull328 Jan 21, 2017
b0f8ba7
added action and method to new Org
jbull328 Jan 21, 2017
8bd41a8
added log
jbull328 Jan 21, 2017
7b147d8
added log
jbull328 Jan 21, 2017
fdedb4d
added log
jbull328 Jan 21, 2017
d43f1a7
added customer route
jbull328 Jan 21, 2017
7a91b39
added customer route
jbull328 Jan 21, 2017
39e39e3
added customer route
jbull328 Jan 21, 2017
1c270af
added customer route
jbull328 Jan 21, 2017
9b6f243
added customer route
jbull328 Jan 21, 2017
83cf497
added new customer post route
jbull328 Jan 21, 2017
a4ac64a
added new customer post route
jbull328 Jan 21, 2017
fd43ca9
N/A
jbull328 Jan 21, 2017
5ab4ee3
N/A
jbull328 Jan 21, 2017
9a2abf0
N/A
jbull328 Jan 21, 2017
71ca404
N/A
jbull328 Jan 21, 2017
29d69c2
N/A
jbull328 Jan 21, 2017
3f72b0a
N/A
jbull328 Jan 21, 2017
86f02cb
N/A
jbull328 Jan 21, 2017
055fa56
N/A
jbull328 Jan 21, 2017
eeeba2a
N/A
jbull328 Jan 21, 2017
eca0698
N/A
jbull328 Jan 21, 2017
6010232
N/A
jbull328 Jan 21, 2017
3d125cd
N/A
jbull328 Jan 21, 2017
9628800
N/A
jbull328 Jan 21, 2017
3d42a70
N/A
jbull328 Jan 21, 2017
6ff579a
N/A
jbull328 Jan 21, 2017
7ba50d3
N/A
jbull328 Jan 21, 2017
a8b4b9d
N/A
jbull328 Jan 21, 2017
ef03daf
N/A
jbull328 Jan 21, 2017
b77496e
N/A
jbull328 Jan 21, 2017
64d7cd4
JOHNBULLL
jbull328 Jan 21, 2017
96617ff
JOHNBULLL
jbull328 Jan 21, 2017
df66f06
JOHNBULLL
jbull328 Jan 21, 2017
63135bc
JOHNBULLL
jbull328 Jan 21, 2017
c50842f
JOHNBULLL
jbull328 Jan 21, 2017
70ed7db
N/A
jbull328 Jan 21, 2017
828218b
N/A
jbull328 Jan 21, 2017
4b21c1e
N/A
jbull328 Jan 21, 2017
2df206e
N/A
jbull328 Jan 21, 2017
3942fe5
N/A
jbull328 Jan 21, 2017
72e7b02
N/A
jbull328 Jan 21, 2017
3838b54
N/A
jbull328 Jan 21, 2017
f9635f7
N/A
jbull328 Jan 21, 2017
5d536af
N/A
jbull328 Jan 21, 2017
d28f0c0
N/A
jbull328 Jan 21, 2017
d0075da
N/A
jbull328 Jan 21, 2017
64b2ec1
N/A
jbull328 Jan 21, 2017
c409296
N/A
jbull328 Jan 21, 2017
d1cf89f
N/A
jbull328 Jan 21, 2017
41f5ccf
N/A
jbull328 Jan 21, 2017
77a1384
Add email
jbull328 Jan 21, 2017
29ef172
Add email
jbull328 Jan 21, 2017
c5e7d02
Add email
jbull328 Jan 21, 2017
d2e8f11
Add email
jbull328 Jan 21, 2017
a63d0e8
Add email
jbull328 Jan 21, 2017
0d09368
Add email
jbull328 Jan 21, 2017
fbf0b4b
Add email
jbull328 Jan 21, 2017
164b5af
Add email
jbull328 Jan 21, 2017
0bc97a0
Add email
jbull328 Jan 21, 2017
011faba
Add email
jbull328 Jan 21, 2017
7df5ef8
Add email todb
jbull328 Jan 21, 2017
26ad9e7
Add email todb
jbull328 Jan 21, 2017
ac7a914
added email weekly cron job
jbull328 Jan 21, 2017
ffad383
ui tweeks
jbull328 Jan 21, 2017
f45c6da
Push it
jbull328 Jan 21, 2017
e375279
Push it
jbull328 Jan 21, 2017
d73315a
Push it
jbull328 Jan 21, 2017
0f8002a
Push it
jbull328 Jan 21, 2017
dbf3976
Push it
jbull328 Jan 21, 2017
7cd4584
Push it
jbull328 Jan 21, 2017
2f2ba39
Push it
jbull328 Jan 21, 2017
440c983
Pushed all the things
jbull328 Jan 21, 2017
bff47dc
Pushed all the things
jbull328 Jan 21, 2017
5a07d66
Pushed all the things
jbull328 Jan 21, 2017
c8a32c4
Pushed all the things
jbull328 Jan 21, 2017
4ceb0c5
Pushed all the things
jbull328 Jan 21, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
STORMPATH_API_KEY_ID=5PC4RW41LP6BJN3WN2X6HN3SU
STORMPATH_API_KEY_SECRET=518jzRbEilz/v2wVyoUD8gmBSzVDusjNLXFh+UyNkFk
STORMPATH_SECRET_KEY=asefasd
STORMPATH_URL= https://api.stormpath.com/v1/applications/7jp6sl4JWZ6kSWzMpXkEFg
MAIL_PASS=krishanmarya1
MAIL_ADDRESS=dummyacct101390
285 changes: 276 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,298 @@
var express = require("express"),
stormpath = require("express-stormpath"),
bodyParser = require("body-parser"),
mongoose = require("mongoose");
app = express();
stormpath = require("express-stormpath"),
bodyParser = require("body-parser"),
MongoClient = require('mongodb').MongoClient,
mongoose = require("mongoose");
app = express();
require('dotenv').config();
nodemailer = require('nodemailer');
const transportString = `smtps://${process.env.MAIL_ADDRESS}%40gmail.com:${process.env.MAIL_PASS}@smtp.gmail.com`;
const transporter = nodemailer.createTransport(transportString);
console.log(transportString);

console.log("HERE I AM!!!",process.env.STORMPATH_API_KEY_ID)
mongoose.Promise = require('bluebird');

let URL = "mongodb://heroku_j1647s3l:tkmie8pbencj50ljm1d688h87e@ds117919.mlab.com:17919/heroku_j1647s3l";



MongoClient.connect(URL, function(err, db) {
if (err) {
URL = 'mongodb://localhost:27017/mydatabase';
} else {
URL = process.env.URL;
}
db.close();
});
mongoose.connect(URL);

console.log("HERE I AM!!!", process.env.STORMPATH_API_KEY_ID)
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
app.use(express.static(__dirname + "/public"));
app.use(stormpath.init(app, {
apiKeyFile: '/.stormpath/apiKey.properties',
apiKeyId: process.env.STORMPATH_API_KEY_ID || "key",
apiKeySecret: process.env.STORMPATH_API_KEY_SECRET || 'secret',
secretKey: process.env.STORMPATH_SECRET_KEY || "key",
application: process.env.STORMPATH_URL || "url",
postLogoutRedirectUrl: '/'

}));

var organizationSchema = new mongoose.Schema({
orgName: String,
givenName: String,
surname: String,
website: String,
});

var Organization = mongoose.model("Organization", organizationSchema);

var customerSchema = new mongoose.Schema({
custFirstName: String,
custLastName: String,
custAddress: String,
cusEmail: String,
organization: String,
clicks: Array,
lastEmailed: Number,
nextScheduled:Number,
});

const organizationalDataAlreadyGiven = (req, res, next) => {
console.log('running middleware!');
Organization.findOne({
givenName: req.user.givenName,
surname: req.user.surname
}, function(err, Organization) {
console.log("Organization", Organization);
if (Organization) {
res.redirect('/customer' + Organization.orgName)
} else {
next();
}
})
};



var Customer = mongoose.model("Customer", customerSchema);


app.get("/", function(req, res) {
res.render("landing");
});

app.get("/newCustomer", function(req, res) {
res.send()
app.post("/getCustomerInfo", stormpath.loginRequired, function(req, res) {
Organization.findOne({
givenName: req.user.givenName,
surname: req.user.surname
}, function(err, Organization) {
Customer.find({
organization: Organization.orgName
}, function(err, people) {
res.send(people);
})
})
});

app.get("/customer:id", stormpath.loginRequired, function(req, res) {
res.render("customer", {
organization: req.params.orgName
});
});

app.listen(process.env.PORT || 3000, function() {
console.log("The CRM Server is running");
app.get("/newOrganization", stormpath.loginRequired, organizationalDataAlreadyGiven,function(req, res) {
res.render("newOrganization");
});

app.post("/newOrganization", stormpath.loginRequired, function(req, res) {
console.log("MY BODY!!!", req.body);
var orgName = req.body.orgName;
var givenName = req.body.givenName;
var surname = req.body.surname;
var website = req.body.website;

var newOrganization = {
orgName,
givenName,
surname,
website,
};

Organization.create(newOrganization, function(err, newlyCreated) {
if (err) {
console.log(err);
} else {
res.redirect("/customer" + orgName);
}
});
});

app.post('/logout', (req, res) => {
console.log('logigin out')
res.redirect('/');
})

app.post("/newCustomer", stormpath.loginRequired, function(req, res) {
console.log('JOHNBULLISWRONG!', req.body);
var custFirstName = req.body.cusFirstName;
var custLastName = req.body.cusLastName;
var custAddress = req.body.cusAddress;
var cusEmail = req.body.cusEmail;
Organization.findOne({
givenName: req.user.givenName,
surname: req.user.surname
}, function(err, organization) {
console.log("here is ORG!", organization);
var newCustomer = {
custFirstName,
custLastName,
custAddress,
cusEmail,
organization: organization.orgName
};
if (err) {
console.log(err);
} else {
Customer.create(newCustomer, function(err, newlyCreated) {
if (err) {
console.log(err);
} else {
//res.redirect("/customer" + orgName);
}
});

};

})
})

app.get("/newEmail", stormpath.loginRequired, function(req, res) {
Organization.findOne({
givenName: req.user.givenName,
surname: req.user.surname
}, function(err, organization) {
res.render(("newEmail"), {
organization,
})
})
});

app.post("/newEmail", stormpath.loginRequired, function(req, res) {

const message = req.body.message;
const header = req.body.header;
const people = req.body.people;
const website = req.body.website;
console.log(message, header, people);

for (let i = 0; i < people.length; i++) {

//check if click are preasent in customer DB
Customer.find({
cusEmail: people[i][3]
}, function(err, person) {
var clickArray = person[0].clicks;
var lastEmailed = person[0].lastEmailed;
var nextScheduled = person[0].nextScheduled;
var currentMill = (new Date()).getTime();
var dontEmail = (currentMill - lastEmailed) < 604800000;
if (!!clickArray.length) {

var latestTime = clickArray[clickArray.length - 1];
var milliseconds = latestTime.getTime();

while (milliseconds < currentMill) {
milliseconds += 604800000;
};
var nextEmail = (new Date(milliseconds));
// if (nextScheduled-currentMill<604800000){
// return;
// }
Customer.update({cusEmail: people[i][3]}, {nextScheduled:milliseconds},function(err, response){
console.log(err,response);
});

console.log(latestTime, "<Letest time", nextEmail, "This the next week", people[i][3]);
var CronJob = require('cron').CronJob;


var job = new CronJob(nextEmail, function() {


var mailOptions = {
from: '"Krishan Arya :busts_in_silhouette:" <dummyacct101390@gmail.com>', // sender address
to: people[i][3], // list of receivers
subject: header, // Subject line
text: `Dear ${people[i][0]}\n` + message, // plaintext body
html: `Dear ${people[i][0]},<br>` + message + "<br><a href='https://mighty-mountain-31348.herokuapp.com/redirect/" + people[i][3] + "'" + ">Interested</a>", // html body
};

transporter.sendMail(mailOptions, function(error, info) {
if (error) {
return console.log(error);
}
console.log('Message sent: ' + info.response);
Customer.update({cusEmail: people[i][3]}, {lastEmailed:nextEmail}, function(err,affected) {
console.log('affected rows %d', affected);
})
});
}, function() {

console.log("Done");
}, true)
} else if(!dontEmail) {

var mailOptions = {
from: '"Krishan Arya :busts_in_silhouette:" <dummyacct101390@gmail.com>', // sender address
to: people[i][3], // list of receivers
subject: header, // Subject line
text: `Dear ${people[i][0]}\n` + message, // plaintext body
html: `Dear ${people[i][0]},<br>` + message + "<br><a href='https://mighty-mountain-31348.herokuapp.com/redirect/" +""+ website +"/"+ people[i][3] + "'" + ">Interested</a>", // html body
};

transporter.sendMail(mailOptions, function(error, info) {
if (error) {
return console.log(error);
}
console.log('Message sent: ' + info.response);
Customer.update({cusEmail: people[i][3]}, {lastEmailed:currentMill}, function(err,affected) {
console.log('affected rows %d', affected);
})
});
}
});

}

});



app.get('/redirect/*', function(req, res) {
console.log("visited2");
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
var email = fullUrl.slice(fullUrl.lastIndexOf('/')+1);
console.log("EMAIL", email,"fu",fullUrl,"website", website);
time = new Date();
Customer.update({cusEmail: email}, {$push: {clicks: time}}, function(err, model) {
console.log(err);
});
res.redirect("google.com");
});

app.get('*', (req, res) => {
res.redirect("http://google.com");
console.log('caught a case!')
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
console.log(fullUrl);
res.redirect('/');
});

app.listen(process.env.PORT || 3000, function() {
console.log("The CRM Server is running");
});
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
"bluebird": "^3.4.7",
"body-parser": "^1.16.0",
"client-sessions": "^0.7.0",
"cron": "^1.2.1",
"dotenv": "^4.0.0",
"ejs": "^2.5.5",
"express": "^4.14.0",
"express-stormpath": "^3.1.9",
"mo": "^1.7.3",
"mongoose": "^4.7.7"
"mongoose": "^4.7.7",
"node-cron": "^1.1.2",
"nodemailer": "^2.7.0"
},
"devDependencies": {
"grunt": "^1.0.1",
Expand Down
Binary file added public/johnbull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 40 additions & 1 deletion public/styles/styles.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@

#orgNameForm {
width: 550px;
}

#emailForm {
margin-top: 50px;
width: 80%;
margin: 0 auto;
}
body {
background-image: url('../johnbull.png');
}
div#customerEntryFull {
top: 20%;
position: relative;
}


body {
background-repeat: no-repeat;
background-size: cover;
}


div#emailForm {
text-align: center;
}

div#orgNameForm {
top: 30%;
position: relative;
}


div#newCusFormMain {
text-align: center;
}
form.ui.form {
text-align: center;
}
.hidden.menu {
display: none;
}
Expand Down Expand Up @@ -77,4 +117,3 @@
font-size: 1.5em;
}
}

Loading