Skip to content

Commit

Permalink
Enable Email
Browse files Browse the repository at this point in the history
  • Loading branch information
Vuthy committed Aug 12, 2019
1 parent 16625ba commit 9e9de11
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ var credentials = {
pass:'yoywnomlwolmysjk'
};

var sEmail = false;
var sEmail = true;

function sendEmail(recipient, subject, text){
var send = require('gmail-send')({
user: credentials.user, // Your GMail account used to send emails
pass: credentials.pass, // Application-specific password
to: recipient, // Send to yourself
user: credentials.user, // Your GMail account used to send emails
pass: credentials.pass, // Application-specific password
to: recipient, // Send to yourself
subject: subject,
html: text, // Plain text
})({}); // Send email without any check
html: text, // Plain text
})({}); // Send email without any check
}

function notSendEmail(recipient, subject, text){

}

if(sEmail){
module.exports = {
sendEmail: sendEmail
}
module.exports = {
sendEmail: sendEmail
}
}else{
module.exports = {
sendEmail: notSendEmail
Expand Down
41 changes: 40 additions & 1 deletion routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,30 @@ module.exports.set = function(router, pool) {

var apartmentFromDatabase = apartment.rows[0].apartment_list; // apartment_list: ['a1', 'a2', 'b3', ...]



// Check apartment from req.body.apartment_list array if it contains in database
for (var i = 0; i < requestBody.apartment_list.length; i++) {
if (apartmentFromDatabase.indexOf(requestBody.apartment_list[i]) == -1 ) {
return res.send(requestBody.apartment_list[i] + " apartment is not exists")
}
}

var userToSendEmail = [];

var fetchEmailQuery = {
text: "SELECT email, apartment, username FROM account;"
}

var emailList = await pool.query(fetchEmailQuery);
for (var i = 0; i < emailList.rows.length; i++) {
if (requestBody.apartment_list.indexOf(emailList.rows[i].apartment) != -1) {
userToSendEmail.push(emailList.rows[i]);
}
}



// If n
if (isNaN(req.body.amount)) {
return res.status(500).send("Amount is in valid number;")
Expand Down Expand Up @@ -400,7 +418,28 @@ module.exports.set = function(router, pool) {
console.log(err)
res.send(err);
} else {
res.send("Sent")
res.send("Sent");

var email = require('../lib/email.js');
// send email to trasferer #shudsdf

// send email to trasferer #shudsdf
for (var i = 0; i < userToSendEmail.length; i++ ) {
console.log("Email to send to: " + userToSendEmail[i].email)
var contentToRecipient = "Hello, "+userToSendEmail[i].username+"<br><br>You have recieved "+parseFloat(req.body.amount)+"P from "+req.user.displayName+"<br><br>Reason: "+req.body.reason+"<br><br><form method=\"get\" action=\"http://ligerpedro.herokuapp.com\"><button class=\"button button1\" style=\"\
background-color: #4CAF50;\
/* Green */\
border: none;\
color: white;\
padding: 2% 2%;\
text-align: center;\
text-decoration: none;\
display: inline-block;\
font-size: 100%;\
cursor: pointer;\">Check it out</button>";
email.sendEmail(userToSendEmail[i].email,"Pedro Recieved",contentToRecipient);
}

}
})

Expand Down

0 comments on commit 9e9de11

Please sign in to comment.