Permalink
Browse files

updated persona api; fixed media bug

  • Loading branch information...
Jen Fong-Adwent
Jen Fong-Adwent committed Sep 12, 2012
1 parent 82fc4ae commit 59ce328d256fa56c5dd68a31a06c29b0a33a64fb
View
1 app.js
@@ -20,6 +20,7 @@ var io = require('socket.io').listen(app);
io.configure(function() {
io.set('transports', ['xhr-polling']);
io.set('polling duration', 10);
+ io.set('log level', 1);
});
io.sockets.on('connection', function(socket) {
View
@@ -12,12 +12,12 @@ exports.verify = function(req, nconf, callback) {
var authUrl = nconf.get('authUrl') + '/verify';
var siteUrl = nconf.get('domain') + ':' + nconf.get('authPort');
- if (!req.body.bid_assertion) {
+ if (!req.body.assertion) {
return callback(new Error('Invalid assertion'));
}
var qs = {
- assertion: req.body.bid_assertion,
+ assertion: req.body.assertion,
audience: siteUrl
};
View
@@ -11,8 +11,8 @@ var PROFILE_MESSAGE_MATCH = /profile-/i;
var ME_MATCH = /^(\/me\s)/i;
var SLASH_MATCHER = /^(\/)\w?/i;
var RECENT_MESSAGE_LIMIT = 19; // limit recent messages to 20, starting at 0
-var RECENT_MEDIA_LIMIT = 4; // limit recent media to 5, starting at 0
-var RECENT_USER_LIMIT = 19; // limit recent users to 20, starting at 0
+var RECENT_MEDIA_LIMIT = 9; // limit recent media to 10, starting at 0
+var RECENT_USER_LIMIT = 39; // limit recent users to 40, starting at 0
var content = require('../lib/web-remix');
var messageMaker = require('../lib/message-maker');
var scaffold = require('../lib/scaffold');
@@ -77,7 +77,6 @@ exports.setRecentMessage = function(client, req, io, callback) {
message.message.match(MEDIA_AUDIO_MATCHER) ||
(message.message.match(MEDIA_IMAGE_MATCHER) &&
message.message.indexOf('class="emoti"') === -1)) {
-
client.lpush('channelMedia:' + channel, jsonMessage);
client.ltrim('channelMedia:' + channel, 0, RECENT_MEDIA_LIMIT);
}
@@ -49,7 +49,7 @@ define(['jquery'],
// if this is a logout trigger, log the user out
} else if(commandMatched(logoutMatcher)) {
commandIsMatched = true;
- document.location.href = '/about/' + $('body').data('channel') + '/logout';
+ navigator.id.logout();
// switch fonts
} else if(commandMatched(fontMatcher)) {
@@ -7,7 +7,7 @@ define(['jquery', 'commands', 'time-format', 'version-timeout'],
var messageList = $('body #messages ol');
var currentChannel = $('body').data('channel');
var logLimit = 80;
- var mediaLimit = 5;
+ var mediaLimit = 10;
var myPost = false;
var mediaIframeMatcher = /<iframe\s.+><\/iframe>/i;
var mediaObjectMatcher = /<object\s.+><\/object>/i;
View
@@ -12,8 +12,8 @@ define(['jquery', 'commands', 'messages', 'users'],
function($, commands, messages, users) {
var currentChannel = $('body').data('channel');
- var loginForm = $('#login');
var messageForm = $('#message');
+ var login = $('#login');
var socket = io.connect(location.protocol + '//' + location.hostname +
(location.port ? ':' + location.port : ''));
@@ -28,23 +28,42 @@ define(['jquery', 'commands', 'messages', 'users'],
users.setUserList(data);
});
- $('#login').click(function() {
- navigator.id.getVerifiedEmail(function(assertion) {
- if (assertion) {
- var loginFormEl = loginForm.find('form');
+ $('#login').click(function(ev) {
+ ev.preventDefault();
+ navigator.id.request();
+ });
- loginFormEl.find('input:first').val(assertion);
- $.post('/about/' + $('body').data('channel') + '/login',
- loginFormEl.serialize(), function (data) {
- loginForm.removeClass('enabled').addClass('disabled');
+ navigator.id.watch({
+ loggedInEmail: currentUser,
+ onlogin: function(assertion) {
+ $.ajax({
+ type: 'POST',
+ url: '/login',
+ data: { assertion: assertion },
+ success: function(res, status, xhr) {
messageForm.removeClass('disabled').addClass('enabled');
- messageForm.find('form').addClass('font' + data.font);
- });
- }
- });
-
- return false;
- });
+ messageForm.find('form').addClass('font' + res.font);
+ login.remove();
+ currentUser = res.email;
+ },
+ error: function(res, status, xhr) {
+ alert('login failure ' + res);
+ }
+ });
+ },
+ onlogout: function() {
+ $.ajax({
+ type: 'GET',
+ url: '/logout',
+ success: function(res, status, xhr) {
+ window.location.reload();
+ },
+ error: function(res, status, xhr) {
+ console.log('logout failure ' + res);
+ }
+ });
+ }
+});
$(window, 'input').focus(function() {
messages.clearUnreadMessages(currentChannel);
View
@@ -6,10 +6,11 @@ var noodleRedis = require('../lib/noodle-redis');
module.exports = function(client, nconf, app, io, isLoggedIn) {
// Login
- app.post('/about/:channel/login', function(req, res) {
+ app.post('/login', function(req, res) {
auth.verify(req, nconf, function(err, email) {
if (err || !email) {
- res.json({ 'status': 500, 'error': err });
+ res.status(500);
+ res.json({ 'error': err });
} else {
var channel = escape(req.params.channel);
@@ -23,17 +24,20 @@ module.exports = function(client, nconf, app, io, isLoggedIn) {
req.session.emailHash = userHash.emailHash;
messageMaker.getMessage(client, channel, req, io, 'joined', function(errMsg, message) {
if (errMsg) {
- res.json({ 'status': 500, 'error': errMsg });
+ res.status(500);
+ res.json({ 'error': errMsg });
} else {
noodleRedis.getUserlist(client, channel, function(errUser, userList) {
if (errUser) {
- res.json({ 'status': 500, 'error': errUser });
+ res.status(500);
+ res.json({ 'error': errUser });
} else {
io.sockets.in(channel).emit('userlist', userList);
io.sockets.in(channel).emit('message', message);
res.json({
+ 'email': req.session.email,
'channel': channel,
'font': req.session.userFont
});
@@ -47,8 +51,10 @@ module.exports = function(client, nconf, app, io, isLoggedIn) {
});
// Logout
- app.get("/about/:channel/logout", isLoggedIn, function(req, res) {
+ app.get('/logout', isLoggedIn, function(req, res) {
req.session.reset();
- res.redirect('/');
+ res.json({
+ 'message': 'logged out'
+ });
});
};
View
@@ -11,20 +11,29 @@ module.exports = function(client, nconf, app, io, isLoggedIn) {
var channel = escape(req.params.channel);
noodleRedis.getRecentMessages(client, channel, function(err, messages) {
if (err) {
- res.json({ 'status': 500, 'error': userErr });
+ res.status(500);
+ res.json({ 'error': err });
} else {
- var channelMessages = {};
+ noodleRedis.getRecentMedia(client, channel, function(errMedia, medias) {
+ if (errMedia) {
+ res.status(500);
+ res.json({ 'error': errMedia });
- channelMessages.generic = messages || {};
- channelMessages.media = {};
+ } else {
+ var channelMessages = {};
- io.sockets.in(channel).emit('userlist', []);
+ channelMessages.generic = messages || {};
+ channelMessages.media = medias || {};
- res.json({
- 'messages': channelMessages,
- 'connected_clients': io.sockets.clients(channel).length,
- 'user_list': []
+ io.sockets.in(channel).emit('userlist', []);
+
+ res.json({
+ 'messages': channelMessages,
+ 'connected_clients': io.sockets.clients(channel).length,
+ 'user_list': []
+ });
+ }
});
}
});
@@ -26,7 +26,7 @@ describe('login', function() {
var params = {
body: {
- bid_assertion: qs.assertion
+ assertion: qs.assertion
}
};
@@ -46,7 +46,7 @@ describe('login', function() {
var params = {
body: {
- bid_assertion: qs.assertion
+ assertion: qs.assertion
}
};
View
@@ -6,8 +6,6 @@ mixin messageForm(enabled)
mixin loginForm(enabled)
a(href='#', id='login', class='#{enabled}') Log in
- form(method='post', action='/about/#{channel}/login', id='login-form')
- input(type='hidden', name='bid_assertion', value='1')
.wrapper
block header
View
@@ -18,6 +18,10 @@ html
!= body
#footer
- script(src='https://browserid.org/include.js', type='text/javascript')
+ script(type='text/javascript')
+ var currentUser = null;
+ if session.email
+ != '<script type="text/javascript">currentUser = "' + session.email + '";</script>'
+ script(src='https://login.persona.org/include.js', type='text/javascript')
script(src='/socket.io/socket.io.js')
script(src='/javascripts/require.js', data-main='/javascripts/main')

0 comments on commit 59ce328

Please sign in to comment.