diff --git a/server/handlers/notifications.js b/server/handlers/notifications.js
new file mode 100644
index 00000000..fa4b137e
--- /dev/null
+++ b/server/handlers/notifications.js
@@ -0,0 +1,39 @@
+var path = require('path');
+
+function requested_change(type, string, channel) {
+ try {
+ var nodemailer = require('nodemailer');
+ var mailconfig = require(path.join(__dirname, '../config/mailconfig.js'));
+
+ let transporter = nodemailer.createTransport(mailconfig);
+
+ transporter.verify(function(error, success) {
+ if (error) {
+ return;
+ } else {
+ var message = "A " + type + " change was requested on " + channel + "
New supposed value is:
" + string + "
\
+ Go to https://admin.zoff.me/ to accept or decline the request.";
+ var msg = {
+ from: 'no-reply@zoff.no',
+ to: 'kasper@zoff.no',
+ subject: 'ZOFF: Requested new ' + type,
+ text: message,
+ html: message,
+ }
+ transporter.sendMail(msg, (error, info) => {
+ if (error) {
+ transporter.close();
+ return;
+ }
+ transporter.close();
+ });
+ }
+ });
+ } catch(e) {
+ console.log(e);
+ console.log("Mail is not configured and wont work");
+ console.log("Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js.");
+ }
+}
+
+module.exports.requested_change = requested_change;
diff --git a/server/handlers/suggestions.js b/server/handlers/suggestions.js
index f9fb5ee3..e67f0b3b 100644
--- a/server/handlers/suggestions.js
+++ b/server/handlers/suggestions.js
@@ -8,6 +8,7 @@ function thumbnail(msg, coll, guid, offline, socket) {
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) {
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){
+ Notifications.requested_change("thumbnail", msg.thumbnail, channel);
socket.emit("toast", "suggested_thumbnail");
});
}
@@ -28,6 +29,7 @@ function description(msg, coll, guid, offline, socket) {
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) {
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){
+ Notifications.requested_change("description", msg.description, channel);
socket.emit("toast", "suggested_description");
});
}
diff --git a/server/index.js b/server/index.js
index d74a056c..13bbb942 100755
--- a/server/index.js
+++ b/server/index.js
@@ -87,6 +87,7 @@ List = require('./handlers/list.js');
Suggestions = require('./handlers/suggestions.js');
ListSettings = require('./handlers/list_settings.js');
Frontpage = require('./handlers/frontpage.js');
+Notifications = require('./handlers/notifications.js');
Search = require('./handlers/search.js');
crypto = require('crypto');
node_cryptojs = require('node-cryptojs-aes');
diff --git a/server/routing/router.js b/server/routing/router.js
index aa4cda54..6ba8a704 100644
--- a/server/routing/router.js
+++ b/server/routing/router.js
@@ -65,7 +65,6 @@ function root(req, res, next) {
javascript_file: "main.min.js",
captcha: res.recaptcha
}
- console.log(data.recaptcha);
res.render('layouts/frontpage', data);
}
} catch(e) {