Permalink
Browse files

First notification test with socket.io

  • Loading branch information...
1 parent 1238f4c commit d680e0212f8eca7194e8a3f3eaa92477f56eee04 @anddimario committed Aug 2, 2012
Showing with 60 additions and 19 deletions.
  1. +6 −0 config.js
  2. +14 −1 controller/user.js
  3. +1 −0 lib/newsite.js
  4. +20 −17 lib/utils.js
  5. +8 −1 proxy.js
  6. +11 −0 views/default.mustache
View
@@ -69,6 +69,12 @@ Config.prototype.Params = {
smtp_password: '',
smtp_ssl: false, // true or false
smtp_from: 'MuContent <info@mucontent.com>',
+
+AWS_KEY: 'AKIAJCEOHDHAQUX34DUA',
+AWS_SECRET: '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',
+AWS_BUCKET: 'digitalgroundtest',
+AWS_BUCKET_DIRECTORY: '/', // default directory where send the files
+
};
module.exports = Config;
View
@@ -221,8 +221,9 @@ function route() {
value.role = "user";
}
user_insert.insert(value, function callbacks(results) {
+ var additional_information = "\nEmail: " + req.body.email + "\nPassword: " + req.body.password;
// send email to user, use function in lib/utils
- utils.send_email(req.headers.host, req.body.email, 'registration', req.body, req.session.lang);
+ utils.send_email(req.headers.host, req.body.email, 'registration', additional_information, req.session.lang);
var message = {
action: '',
reference: 'registrated',
@@ -247,6 +248,18 @@ function route() {
firstname: req.body.firstname,
surname: req.body.surname,
};
+ // get data from cache for the site
+ var site = cache.get(req.headers.host), public_key, private_key;
+ site.forEach( function (row) {
+ if (row.type === "information") {
+ private_key = row.captcha_private_key;
+ public_key = row.captcha_public_key;
+ }
+ });
+ // create and inizialize captcha
+ var recaptcha = new Recaptcha(public_key, private_key);
+ data.captcha = recaptcha.toHTML();
+
utils.rendering(req.headers.host, 'registration', data, req.session.info, req.session.lang, message, function callback(layout) {
res.end(layout);
});
View
@@ -95,6 +95,7 @@ var defaultcontent = [
{ "type": "content", "tag": "langformkeyword", "lang_id": "0", "text": "Keywords for searching, like (key1,key2,...)" },
{ "type": "content", "tag": "langformreference", "lang_id": "0", "text": "Path for content reference" },
{ "type": "content", "tag": "langformsmtpsettings", "lang_id": "0", "text": "SMTP Settings, like: host,username,password,ssl(true or false),from(Acme Ltd <info@acme.com>" },
+{ "type": "template", "tag": "registration", "text": "Site Registration+Hello, here your data:", "lang_id": "0"},
]
var database, information = {}, domain, subdomains, count = 0;
View
@@ -222,42 +222,45 @@ function maintenance(req, res, next) {
/*
domain: the site that send the email
receiver: the mail receiver
-mail_type: the mail type
-mail_information: information useful for template
+mail_tag: the mail tag that you should get into database
+mail_information: additional information useful for template
+lang: language for template resource
*/
-function send_email(domain, mail_receiver, mail_type, mail_information, lang) {
+function send_email(domain, mail_receiver, mail_tag, mail_information, lang) {
var server = email.server.connect({
user: configuration.Params.smtp_user,
password: configuration.Params.smtp_password,
host: configuration.Params.smtp_host,
ssl: configuration.Params.smtp_ssl
});
+ if (!lang) {
+ lang = 0;
+ }
+
var mail_text, mail_subject;
// get template for the mail
var site_lang = cache.get(domain+'_lang');
site_lang.forEach( function (row) {
- if ((row.type === 'template') && (row.lang_id == lang)) {
+ if ((row.type === 'template') && (row.lang_id == lang) && (row.tag === mail_tag)) {
var text = row.text;
mail_subject = text.split('+')[0];
mail_text = text.split('+')[1]+mail_information;
- }
- });
-
// USE TEMPLATE IN CONTENT CONTROLLER LIKE:
// type: 'template', tag: mail_type, text: 'subject+text', lang_id:''
-
- // send the message and get a callback with an error or details of the message that was sent
- server.send({
- text: mail_text,
- from: configuration.Params.smtp_from,
- to: mail_receiver,
- subject: mail_subject
- }, function(err, message) {
- if (err) {
- quicklog("Email log: ", err);
+ // send the message and get a callback with an error or details of the message that was sent
+ server.send({
+ text: mail_text,
+ from: configuration.Params.smtp_from,
+ to: mail_receiver,
+ subject: mail_subject
+ }, function(err, message) {
+ quicklog("Email log: ", message);
+ });
}
+
});
+
}
exports.quicklog = quicklog;
View
@@ -8,6 +8,7 @@ var utils = require('./lib/utils');
var cache = require('memory-cache');
var Config = require('./config');
var exec = require('child_process').exec;
+var sio = require('socket.io');
var configuration = new Config();
@@ -23,7 +24,13 @@ Server.prototype.start = function () {
utils.quicklog('Network shared ip configuration ', stderr, stdout);
});
}
- http.createServer(this.proxy).listen(80, configuration.Params.heartbeat_ip);
+ var server = http.createServer(this.proxy).listen(80, configuration.Params.heartbeat_ip);
+ // Start socket.io for messages
+ var io = sio.listen(server);
+ io.sockets.on('connection', function (socket) {
+ socket.emit('notification', { hello: 'world' });
+ });
+
utils.quicklog("Start server");
}
View
@@ -92,6 +92,8 @@
<!-- THE MESSAGE -->
<div class='alert fade in {{action}}'>{{message}} <a class='close' data-dismiss='alert' href='#'>&times;</a></div>
{{/message}}
+<!-- THE MUCONTENT NOTIFICATION -->
+ <div id='notification' class='alert fade in'></div>
{{#staticcontent}}
<!-- THE PAGE CONTENT -->
@@ -340,6 +342,15 @@
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script src='/js/bootstrap-dropdown.js'></script>
<script src='/js/bootstrap-alert.js'></script>
+<!-- MuContent notification script -->
+ <script src="/socket.io/socket.io.js"></script>
+ <script>
+ $('#notification').hide(); // Hide div by default
+ var client = io.connect();
+ client.on('notification', function (message) { $('#notification').toggle().text(message).append('<a class=close data-dismiss=alert href=#>&times;</a>'); });
+
+ </script>
+
</body>
</html>

0 comments on commit d680e02

Please sign in to comment.