Permalink
Browse files

added error pages; profile page

  • Loading branch information...
1 parent dca987e commit d1f4f27dc1b494818981cf262dc03e4b81c9cc11 Jen Fong-Adwent committed Jul 4, 2012
View
35 app.js
@@ -3,40 +3,53 @@ var noodle = require('./package');
var express = require('express');
var configurations = module.exports;
var app = express.createServer();
-var redis = require("redis");
+var redis = require('redis');
var client = redis.createClient();
var nconf = require('nconf');
var settings = require('./settings')(app, configurations, express);
nconf.argv().env().file({ file: 'local.json' });
client.select(app.set('redisnoodle'), function(errDb, res) {
- console.log('PROD/DEV database connection status: ', res);
+ console.log(process.env.NODE_ENV || 'dev' + ' database connection status: ', res);
});
// Always set noodletalk as an available channel and never expire it
client.set('channels:noodletalk', 'noodletalk');
var io = require('socket.io').listen(app);
-io.configure(function () {
- io.set("transports", ["xhr-polling"]);
- io.set("polling duration", 10);
+io.configure(function() {
+ io.set('transports', ['xhr-polling']);
+ io.set('polling duration', 10);
});
-io.sockets.on('connection', function (socket) {
- socket.on('join channel', function (channel) {
+io.sockets.on('connection', function(socket) {
+ socket.on('join channel', function(channel) {
socket.join(channel);
});
- socket.on('private', function (data) {
+ socket.on('private', function(data) {
io.sockets.in(data.channel).emit('private', data.privateChannel);
});
});
// routes
-require("./routes")(client, noodle, nconf, app, io);
-require("./routes/message")(client, nconf, app, io);
-require("./routes/auth")(client, nconf, app, io);
+require('./routes')(client, noodle, nconf, app, io);
+require('./routes/message')(client, nconf, app, io);
+require('./routes/auth')(client, nconf, app, io);
+
+app.get('/404', function(req, res, next){
+ next();
+});
+
+app.get('/403', function(req, res, next){
+ err.status = 403;
+ next(new Error('not allowed!'));
+});
+
+app.get('/500', function(req, res, next){
+ next(new Error('something went wrong!'));
+});
app.listen(process.env.PORT || nconf.get('port'));
View
@@ -1,5 +1,5 @@
+const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/';
var crypto = require('crypto');
-var gravatar = require('gravatar');
var request = require('request');
/* Browser ID authentication
@@ -46,10 +46,16 @@ exports.verify = function(req, nconf, callback) {
};
// Return a hash of the public user metadata
-exports.getUserHash = function(req, nickname, channel, callback) {
+exports.getUserHash = function(req, nickname, channel, isOwner, callback) {
+ if (isOwner) {
+ var emailHash = crypto.createHash('md5').update(req.session.email).digest("hex");
+ } else {
+ var emailHash = req.params.email;
+ }
+
var user = {
- emailHash: crypto.createHash('md5').update(req.session.email).digest("hex"),
- avatar: gravatar.url(req.session.email, {}, true),
+ emailHash: emailHash,
+ avatar: GRAVATAR_URL + emailHash,
nickname: nickname
};
View
@@ -59,64 +59,68 @@ exports.getMessage = function(client, channel, req, io, actionType, callback) {
return callback(errCnt);
}
- var newNickname = content.getNickName(req.body.message);
+ try {
+ var newNickname = content.getNickName(req.body.message);
- var oldNickname = self.nicknameIsEmpty(req.session.nickname[channel]);
- var nickname = oldNickname;
+ var oldNickname = self.nicknameIsEmpty(req.session.nickname[channel]);
+ var nickname = oldNickname;
- if (newNickname) {
- nickname = newNickname;
- }
-
- req.session.nickname[channel] = nickname;
-
- auth.getUserHash(req, nickname, channel, function(errHash, userHash) {
- if (errHash) {
- return callback(errHash);
+ if (newNickname) {
+ nickname = newNickname;
}
- noodleRedis.setChannelUser(client, channel, userHash, oldNickname, newNickname, function(err, usernameUsed) {
- if (err) {
- return callback(err);
- }
-
- // if this is a /nick change, check to see if we can set it
- if (actionType === "nick") {
- if (!usernameUsed) {
- message = '<em>' + oldNickname + ' has changed to ' + newNickname + '</em>';
- req.session.nickname[channel] = newNickname;
- req.session.updated = new Date();
+ req.session.nickname[channel] = nickname;
- noodleRedis.getUserlist(client, channel, function(err, userList) {
- io.sockets.in(channel).emit('userlist', userList);
- io.sockets.in(channel).emit('userHash', userHash);
- });
+ auth.getUserHash(req, nickname, channel, true, function(errHash, userHash) {
+ if (errHash) {
+ return callback(errHash);
+ }
- } else {
+ noodleRedis.setChannelUser(client, channel, userHash, oldNickname, newNickname, function(err, usernameUsed) {
+ if (err) {
+ return callback(err);
+ }
+
+ // if this is a /nick change, check to see if we can set it
+ if (actionType === "nick") {
+ if (!usernameUsed) {
+ message = '<em>' + oldNickname + ' has changed to ' + newNickname + '</em>';
+ req.session.nickname[channel] = newNickname;
+ req.session.updated = new Date();
+
+ noodleRedis.getUserlist(client, channel, function(err, userList) {
+ io.sockets.in(channel).emit('userlist', userList);
+ io.sockets.in(channel).emit('userHash', userHash);
+ });
+
+ } else {
+ message = '';
+ }
+ isAction = true;
+
+ // if this is a /me prepend with the nick
+ } else if (actionType === "activity") {
+ var meMatch = /^(\s\/me\s?)/i;
+ message = '<em>' + req.session.nickname[channel] + ' ' + message.replace(meMatch, '') + '</em>';
+ isAction = true;
+
+ // user joining new channel
+ } else if (actionType === "joined") {
+ message = self.generateWelcomeMessage();
+ isAction = true;
+
+ // clear invalid commands
+ } else if (actionType === "dummy") {
message = '';
- }
- isAction = true;
-
- // if this is a /me prepend with the nick
- } else if (actionType === "activity") {
- var meMatch = /^(\s\/me\s?)/i;
- message = '<em>' + req.session.nickname[channel] + ' ' + message.replace(meMatch, '') + '</em>';
- isAction = true;
-
- // user joining new channel
- } else if (actionType === "joined") {
- message = self.generateWelcomeMessage();
- isAction = true;
-
- // clear invalid commands
- } else if (actionType === "dummy") {
- message = '';
- }
+ }
- message = self.generateMessage(message);
+ message = self.generateMessage(message);
- return callback(null, message);
+ return callback(null, message);
+ });
});
- });
+ } catch (msgErr) {
+ return callback(msgErr);
+ }
});
};
Oops, something went wrong.

0 comments on commit d1f4f27

Please sign in to comment.