Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Canop/miaou
Browse files Browse the repository at this point in the history
  • Loading branch information
ralt committed Feb 19, 2014
2 parents 220e4e8 + 564c53a commit 79e8436
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion login.js
Expand Up @@ -111,7 +111,7 @@ var toUrlDecoration = exports.toUrlDecoration = function(roomName){
}

exports.isValidUsername = function(username){
return username && /^\w[\w_\-\d]{2,19}$/.test(username);
return !!(username && /^\w[\w_\-\d]{2,19}$/.test(username));
}

exports.test = function(){
Expand Down
11 changes: 8 additions & 3 deletions main.js
Expand Up @@ -48,6 +48,9 @@ function roomUrl(room){
strategyConstructor: require('passport-stackexchange').Strategy
}, github: {
strategyConstructor: require('passport-github').Strategy
}, reddit: {
strategyConstructor: require('passport-reddit').Strategy,
scope: 'identity'
}
};
var oauthConfigs = config.oauth2;
Expand Down Expand Up @@ -129,7 +132,7 @@ function defineAppRoutes(){
var externalProfileInfos = plugins.filter(function(p){ return p.externalProfile}).map(function(p){
return { name:p.name, ep:p.externalProfile, fields:p.externalProfile.creation.fields }
});
var error;
var error = '';
db.on(externalProfileInfos)
.map(function(epi){
return this.getPlayerPluginInfo(epi.name, req.user.id);
Expand Down Expand Up @@ -178,10 +181,12 @@ function defineAppRoutes(){
externalProfileInfos.forEach(function(epi){
if (epi.ep.creation.describe) epi.creationDescription = epi.ep.creation.describe(req.user);
});
var hasValidName = loginutil.isValidUsername(req.user.name);
res.render('profile.jade', {
user: req.user,
externalProfileInfos: externalProfileInfos,
suggestedName: loginutil.isValidUsername(req.user.name) ? req.user.name : loginutil.suggestUsername(req.user.oauthdisplayname || ''),
valid : hasValidName,
suggestedName: hasValidName ? req.user.name : loginutil.suggestUsername(req.user.oauthdisplayname || ''),
error: error
});
}).catch(function(err){
Expand All @@ -191,7 +196,7 @@ function defineAppRoutes(){

for (var key in oauth2Strategies){
var s = oauth2Strategies[key];
app.get('/auth/'+key, passport.authenticate(key, {scope:s.scope}));
app.get('/auth/'+key, passport.authenticate(key, {scope:s.scope, state:'Ohio', duration:'permanent'}));
app.get('/auth/'+key+'/callback', passport.authenticate(key, { failureRedirect: '/login' }), function(req, res) { res.redirect(url()) });
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -21,8 +21,9 @@
"connect-redis": "~1.4.6",
"passport-google-oauth": "~0.1.5",
"passport-stackexchange": "~0.1.0",
"passport-github": "~0.1.5"
},
"passport-github": "~0.1.5",
"passport-reddit": "~0.2.4"
},
"scripts": {
"start": "sh start.sh"
}
Expand Down
6 changes: 3 additions & 3 deletions pgdb.js
Expand Up @@ -27,8 +27,8 @@ NoRowError.prototype = Object.create(Error.prototype);
// Private fields are included in the returned object
proto.getCompleteUserFromOAuthProfile = function(profile){
console.dir(profile);
var oauthid = profile.id || profile.user_id, // id for google and github, user_id for stackexchange
displayName = profile.displayName || profile.display_name, // displayName for google and github, display_name for stackexchange
var oauthid = profile.id || profile.user_id, // id for google, github and reddit, user_id for stackexchange
displayName = profile.displayName || profile.display_name || profile.name, // displayName for google and github, display_name for stackexchange, name for reddit
provider = profile.provider;
if (!oauthid) throw new Error('no id found in OAuth profile');
var con = this, resolver = Promise.defer(),
Expand Down Expand Up @@ -426,7 +426,7 @@ proto.off = function(){
proto.queryRow = function(sql, args, noErrorOnNoRow){
var resolver = Promise.defer();
this.client.query(sql, args, function(err, res){
logQuery(sql, args);
//~ logQuery(sql, args);
if (err) {
resolver.reject(err);
} else if (res.rows.length) {
Expand Down
3 changes: 2 additions & 1 deletion views/login.jade
Expand Up @@ -34,7 +34,8 @@ html
var names = {
google: "<span class=icon>&#xe818;</span> Google",
stackexchange: "<span class=icon>&#xe816;</span> StackExchange",
github: "<span class=icon>&#xe817;</span> GitHub"
github: "<span class=icon>&#xe817;</span> GitHub",
reddit: "<span class=icon>&#xe819;</span> reddit"
};
for (var key in strategies) {
(function(key, strategy){
Expand Down
12 changes: 7 additions & 5 deletions views/profile.jade
Expand Up @@ -38,19 +38,19 @@ html
input(type=(field.type||'text'),name=field.name)
if ep.creationDescription
p !{ep.creationDescription}
if error
p#err.error= error
p#err.error= error
div.dialog_buttons
button#submit Save
button#close Close
button#close Go On

script.
var externalProfileInfos = !{JSON.stringify(externalProfileInfos)};
var externalProfileInfos = !{JSON.stringify(externalProfileInfos)},
valid = !{JSON.stringify(valid)};
$('#name').focus().keyup(function(){
if (!this.validity.valid){ // not compatible with IE, that's fine
$('#err').text('Please type a name with 3 to 20 standard characters, digits, "_" or "-"');
$('#submit').prop('disabled', true);
} else if (/wisely/i.test(this.value)) {
} else if (/w+[_-]*[iy]+[_-]*s+[_-]*e+[_-]*l+[_-]*[iy]+/i.test(this.value)) {
$('#err').text('More wisely, less "wisely", please.');
$('#submit').prop('disabled', true);
} else {
Expand All @@ -60,6 +60,8 @@ html
});
$('#close').click(function(){ location = 'rooms'; return false; });

if (!valid) $('#close').hide();

$('.sectionOpener + section').hide();
$('.sectionOpener').click(function(){
$(this).toggleClass('sectionOpener sectionCloser').next('section').toggle();
Expand Down
1 change: 1 addition & 0 deletions ws.js
Expand Up @@ -199,6 +199,7 @@ function handleUserInRoom(socket, completeUser, db){
reply(results);
}).finally(db.off);
}).on('hist', function(search, reply){
if (!room) return reply([]);
db.on(room.id)
.then(db.messageHistogram)
.then(function(hist){
Expand Down

0 comments on commit 79e8436

Please sign in to comment.