-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,356 additions
and
199 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,10 @@ | ||
module.exports = { | ||
"extends": "airbnb", | ||
"env": { | ||
"node": true | ||
}, | ||
"rules": { | ||
"strict": 0, | ||
"no-var": 0 | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules/ | ||
.DS_Store | ||
.DS_Store | ||
|
||
config.js |
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 |
---|---|---|
@@ -1,66 +1,67 @@ | ||
var express = require('express'); | ||
|
||
var app = express(); | ||
var router = express.Router(); | ||
var https = require('https'); | ||
var nodemailer = require('nodemailer'); | ||
// var https = require('https'); | ||
// var nodemailer = require('nodemailer'); | ||
|
||
var server = require('./server.js'); | ||
/* | ||
configuring our SMTP Server details. | ||
STMP is mail server which is responsible for sending and recieving email. | ||
*/ | ||
var smtpTransport = nodemailer.createTransport("SMTP",{ | ||
service: "Gmail", | ||
auth: { | ||
user: "Your Gmail ID", | ||
pass: "Gmail Password" | ||
} | ||
}); | ||
/* | ||
configuring our SMTP Server details. | ||
STMP is mail server which is responsible for sending and recieving email. | ||
*/ | ||
var smtpTransport = nodemailer.createTransport("SMTP", { | ||
service: "Gmail", | ||
auth: { | ||
user: "Your Gmail ID", | ||
pass: "Gmail Password" | ||
} | ||
}); | ||
|
||
var rand,mailOptions,host,link; | ||
var rand, mailOptions, host, link; | ||
|
||
/*------------------SMTP Over-----------------------------*/ | ||
/*------------------SMTP Over-----------------------------*/ | ||
|
||
/*------------------Routing Started ------------------------*/ | ||
|
||
app.get('/send',function(req,res){ | ||
rand = Math.floor((Math.random() * 100) + 54); | ||
host = req.get('host'); | ||
link="http://"+req.get('host')+"/verify?id="+rand; | ||
mailOptions={ | ||
to : req.query.to, | ||
subject : "Question", | ||
html : "Hello,<br> Please Click on the link to verify your email.<br> <a href=" + link + ">Click here to verify</a>" | ||
} | ||
console.log(mailOptions); | ||
smtpTransport.sendMail(mailOptions, function(err, response){ | ||
if(err){ | ||
console.log(err); | ||
res.end("error"); | ||
}else{ | ||
console.log("Message sent: " + response.message); | ||
res.end("sent"); | ||
} | ||
}); | ||
}); | ||
app.get('/send', function (req, res) { | ||
rand = Math.floor((Math.random() * 100) + 54); | ||
host = req.get('host'); | ||
link = "http://" + req.get('host') + "/verify?id=" + rand; | ||
mailOptions = { | ||
to: req.query.to, | ||
subject: "Question", | ||
html: "Hello,<br> Please Click on the link to verify your email.<br> <a href=" + link + ">Click here to verify</a>" | ||
} | ||
console.log(mailOptions); | ||
smtpTransport.sendMail(mailOptions, function (err, response) { | ||
if (err) { | ||
console.log(err); | ||
res.end("error"); | ||
} else { | ||
console.log("Message sent: " + response.message); | ||
res.end("sent"); | ||
} | ||
}); | ||
}); | ||
|
||
app.get('/verify',function(req,res){ | ||
console.log(req.protocol + ":/" + req.get('host')); | ||
if((req.protocol+"://"+req.get('host'))==("http://"+host)) | ||
{ | ||
app.get('/verify', function (req, res) { | ||
console.log(req.protocol + ":/" + req.get('host')); | ||
if ((req.protocol + "://" + req.get('host')) == ("http://" + host)) { | ||
console.log("Domain is matched. Information is from Authentic email"); | ||
if(req.query.id==rand){ | ||
console.log("email is verified"); | ||
res.end("<h1>Email "+mailOptions.to+" has been Successfully verified"); | ||
} | ||
else{ | ||
console.log("email is not verified"); | ||
res.end("<h1>Bad Request.</h1><p>Email is not verified, does not work, or just doesn't exist. Try again.</p>"); | ||
} | ||
if (req.query.id == rand) { | ||
console.log("email is verified"); | ||
res.end("<h1>Email " + mailOptions.to + " has been Successfully verified"); | ||
} | ||
else { res.end("<h1>Request is from unknown source"); | ||
else { | ||
console.log("email is not verified"); | ||
res.end("<h1>Bad Request.</h1><p>Email is not verified, does not work, or just doesn't exist. Try again.</p>"); | ||
} | ||
} | ||
else { | ||
res.end("<h1>Request is from unknown source"); | ||
} | ||
}); | ||
|
||
/*--------------------Routing Over----------------------------*/ | ||
module.exports = router; | ||
/*--------------------Routing Over----------------------------*/ | ||
module.exports = router; |
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 @@ | ||
var express = require('express'); | ||
var bodyParser = require('body-parser'); | ||
var dB = require('./mongo'); | ||
var app = express(); | ||
|
||
var questionsRouter = require('./routes/questions'); | ||
|
||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
// respond with "hello world" when a GET request is made to the homepage | ||
app.get('/', (req, res) => { | ||
res.send('hello world'); | ||
}); | ||
|
||
questionsRouter.get('/', (req, res) => { | ||
res.send('send all the questions with responses here'); | ||
}); | ||
|
||
app.use('/questions', questionsRouter); | ||
|
||
dB.start(); | ||
|
||
app.listen('3000'); |
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,23 @@ | ||
var config = require('../config'); | ||
var MongoClient = require('mongodb').MongoClient | ||
, assert = require('assert'); | ||
|
||
// Connection URL | ||
var url = config.mongoUrl; | ||
// Use connect method to connect to the Server | ||
|
||
var db = null; | ||
|
||
module.exports = { | ||
start: () => { | ||
MongoClient.connect(url, (err, database) => { | ||
if (err) { | ||
console.log(`err: ${err}`) | ||
} else { | ||
console.log("Connected correctly to server"); | ||
db = database; | ||
} | ||
}); | ||
}, | ||
get: () => db, | ||
}; |
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,25 @@ | ||
var express = require('express'); | ||
var dB = require('../mongo'); | ||
var questionsRouter = express.Router(); | ||
|
||
questionsRouter.get('/', (req, res) => { | ||
res.send('send all the questions with responses here'); | ||
}); | ||
|
||
questionsRouter.post('/ask', (req, res) => { | ||
console.log('question received'); | ||
console.log(req.body); | ||
const db = dB.get(); | ||
const collection = db.collection('questions'); | ||
collection.insert(req.body, (err, result) => { | ||
if (err) { | ||
console.log(`err: ${err}`); | ||
} else { | ||
console.log('inserted'); | ||
console.log(result); | ||
} | ||
}); | ||
res.send('you sent a question'); | ||
}); | ||
|
||
module.exports = questionsRouter; |
Oops, something went wrong.