Pull in a bunch of changes from private branch, initial everyauth code
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
// Generated by CoffeeScript 1.3.3
|
||||
var conf, derby, model, sess;
|
||||
|
||||
conf = require("./conf");
|
||||
|
||||
derby = require('derby');
|
||||
|
||||
model = void 0;
|
||||
|
||||
sess = void 0;
|
||||
|
||||
module.exports.setupPurlAuth = function(req) {
|
||||
var acceptableUid, uidParam;
|
||||
model = req.getModel();
|
||||
sess = req.session;
|
||||
sess.userId || (sess.userId = derby.uuid());
|
||||
sess.auth || (sess.auth = {
|
||||
userId: sess.userId
|
||||
});
|
||||
uidParam = req.url.split('/')[1];
|
||||
acceptableUid = require('guid').isGuid(uidParam) || (uidParam === '3' || uidParam === '9');
|
||||
if (acceptableUid && sess.userId !== uidParam) {
|
||||
sess.userId = uidParam;
|
||||
}
|
||||
return model.set('_userId', sess.userId);
|
||||
};
|
||||
|
||||
module.exports.setupEveryauth = function(everyauth) {
|
||||
everyauth.debug = true;
|
||||
everyauth.everymodule.findUserById(function(id, callback) {
|
||||
return model.fetch("users." + id, function(err, user) {
|
||||
var content, guid, newUser, schema, task, _i, _len, _ref;
|
||||
if (user && user.get('id')) {
|
||||
return callback(null, user.get());
|
||||
} else {
|
||||
schema = require('../app/schema');
|
||||
content = require('../app/content');
|
||||
newUser = require('node.extend')(true, {}, schema.userSchema);
|
||||
_ref = content.defaultTasks;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
task = _ref[_i];
|
||||
guid = task.id = require('derby/node_modules/racer').uuid();
|
||||
newUser.tasks[guid] = task;
|
||||
switch (task.type) {
|
||||
case 'habit':
|
||||
newUser.habitIds.push(guid);
|
||||
break;
|
||||
case 'daily':
|
||||
newUser.dailyIds.push(guid);
|
||||
break;
|
||||
case 'todo':
|
||||
newUser.todoIds.push(guid);
|
||||
break;
|
||||
case 'reward':
|
||||
newUser.rewardIds.push(guid);
|
||||
}
|
||||
}
|
||||
model.set("users." + id, newUser);
|
||||
return callback(null, newUser);
|
||||
}
|
||||
});
|
||||
});
|
||||
return everyauth.facebook.appId(process.env.FACEBOOK_KEY).appSecret(process.env.FACEBOOK_SECRET).findOrCreateUser(function(session, accessToken, accessTokenExtra, fbUserMetadata) {
|
||||
var q;
|
||||
q = model.query('users').withEveryauth('facebook', fbUserMetadata.id);
|
||||
model.fetch(q, function(err, user) {
|
||||
console.log({
|
||||
err: err,
|
||||
user: user
|
||||
});
|
||||
if (user.get('id')) {
|
||||
return sess.userId = user.get('id');
|
||||
} else {
|
||||
model.setNull("users." + sess.userId + ".auth", {
|
||||
'facebook': {}
|
||||
});
|
||||
return model.set("users." + sess.userId + ".auth.facebook", fbUserMetadata);
|
||||
}
|
||||
});
|
||||
return fbUserMetadata;
|
||||
}).redirectPath("/");
|
||||
};
|
||||
|
||||
module.exports.setupQueries = function(store) {
|
||||
store.query.expose('users', 'withId', function(id) {
|
||||
return this.byId(id);
|
||||
});
|
||||
store.query.expose('users', 'withEveryauth', function(provider, id) {
|
||||
console.log({
|
||||
withEveryauth: {
|
||||
provider: provider,
|
||||
id: id
|
||||
}
|
||||
});
|
||||
return this.where("auth." + provider + ".id").equals(id);
|
||||
});
|
||||
return store.queryAccess('users', 'withEveryauth', function(methodArgs) {
|
||||
var accept;
|
||||
accept = arguments[arguments.length - 1];
|
||||
return accept(true);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.setupAccessControl = function(store) {
|
||||
store.accessControl = true;
|
||||
store.readPathAccess('users.*', function() {
|
||||
var captures, next;
|
||||
if (!(this.session && this.session.userId)) {
|
||||
return;
|
||||
}
|
||||
captures = arguments[0];
|
||||
next = arguments[arguments.length - 1];
|
||||
return next(captures === this.session.userId);
|
||||
});
|
||||
return store.writeAccess('*', 'users.*', function() {
|
||||
var captures, next, pathArray;
|
||||
if (!(this.session && this.session.userId)) {
|
||||
return;
|
||||
}
|
||||
captures = arguments[0];
|
||||
next = arguments[arguments.length - 1];
|
||||
pathArray = captures.split('.');
|
||||
return next(pathArray[0] === this.session.userId);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,121 @@
|
||||
// Generated by CoffeeScript 1.3.3
|
||||
|
||||
module.exports = {
|
||||
fb: {
|
||||
appId: "439694562721556",
|
||||
appSecret: "d34327a67e32fe7936ababb72fa9639e"
|
||||
},
|
||||
twit: {
|
||||
consumerKey: "JLCGyLzuOK1BjnKPKGyQ",
|
||||
consumerSecret: "GNqKfPqtzOcsCtFbGTMqinoATHvBcy1nzCTimeA9M0"
|
||||
},
|
||||
github: {
|
||||
appId: "11932f2b6d05d2a5fa18",
|
||||
appSecret: "2603d1bc663b74d6732500c1e9ad05b0f4013593"
|
||||
},
|
||||
instagram: {
|
||||
clientId: "be147b077ddf49368d6fb5cf3112b9e0",
|
||||
clientSecret: "b65ad83daed242c0aa059ffae42feddd"
|
||||
},
|
||||
foursquare: {
|
||||
clientId: "VUGE4VHJMKWALKDKIOH1HLD1OQNHTC0PBZZBUQSHJ3WKW04K",
|
||||
clientSecret: "0LVAGARGUN05DEDDRVWNIMH4RFIHEFV0CERU3OITAZW1CXGX"
|
||||
},
|
||||
gowalla: {
|
||||
apiKey: "11cf666912004d709fa4bbf21718a82e",
|
||||
apiSecret: "e1e23f135776452898a6d268129bf153"
|
||||
},
|
||||
linkedin: {
|
||||
apiKey: "pv6AWspODUeHIPNZfA531OYcFyB1v23u3y-KIADJdpyw54BXh-ciiQnduWf6FNRH",
|
||||
apiSecret: "Pdx7DCoJRdAk0ai3joXsslZvK1DPCQwsLn-T17Opkae22ZYDP5R7gmAoFes9TNHy"
|
||||
},
|
||||
google: {
|
||||
clientId: "3335216477.apps.googleusercontent.com",
|
||||
clientSecret: "PJMW_uP39nogdu0WpBuqMhtB"
|
||||
},
|
||||
googlehybrid: {
|
||||
consumerKey: "YOUR CONSUMER KEY HERE",
|
||||
consumerSecret: "YOUR CONSUMER SECRET HERE"
|
||||
},
|
||||
_37signals: {
|
||||
clientId: "cd4bf9cd9ed828b6bed8b67e6b314cf8b90c8de5",
|
||||
clientSecret: "07883c36b4f4493b70f31872ed8fbdb099ff1cef"
|
||||
},
|
||||
angellist: {
|
||||
clientId: "e5feda9308f55f16b0ef0e848f5b1e41",
|
||||
clientSecret: "e0ec367efb9d59fa10bdd53ba268b81f"
|
||||
},
|
||||
yahoo: {
|
||||
consumerKey: "dj0yJmk9RVExRlhPRE9rV1hSJmQ9WVdrOWEyRTBVMUJoTm1zbWNHbzlNVE13TURFeU9UTTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iYg--",
|
||||
consumerSecret: "efe6ae4982217630fe3aebf6e6fa1e82c02eba0b"
|
||||
},
|
||||
readability: {
|
||||
consumerKey: "Alfrednerstu",
|
||||
consumerSecret: "MXGftcxrRNMYn66CVmADR3KRnygCdYSk"
|
||||
},
|
||||
justintv: {
|
||||
consumerKey: "enter your consumer key here",
|
||||
consumerSecret: "enter your consumer secret here"
|
||||
},
|
||||
tumblr: {
|
||||
consumerKey: "TAofjqRz9iKiAjtPMnXzHELIeQAw8cqKCZVXaEFSAxBrrvV99f",
|
||||
consumerSecret: "s8ldFtirtsnWGSiBjwpUwMct8Yh4sliS9Uiocqsv3bw0ovMtlR"
|
||||
},
|
||||
dropbox: {
|
||||
consumerKey: "uhfqnbely5stdtm",
|
||||
consumerSecret: "jr7ofuwo32l7vkd"
|
||||
},
|
||||
vimeo: {
|
||||
consumerKey: "Enter your consumer key here",
|
||||
consumerSecret: "Enter your consumer secret here"
|
||||
},
|
||||
box: {
|
||||
apiKey: "5hl66lbfy0quj8qhhzcn57dflb55y4rg"
|
||||
},
|
||||
dwolla: {
|
||||
clientId: "Enter your consumer key here",
|
||||
clientSecret: "Enter your consumer secret here"
|
||||
},
|
||||
vkontakte: {
|
||||
appId: "Enter your app id here",
|
||||
appSecret: "Enter your app secret here"
|
||||
},
|
||||
mailru: {
|
||||
appId: "Enter your app id here",
|
||||
appSecret: "Enter your app secret here"
|
||||
},
|
||||
skyrock: {
|
||||
consumerKey: "a0ae943e20c5af88",
|
||||
consumerSecret: "cjucy86r0fg4uxx3"
|
||||
},
|
||||
evernote: {
|
||||
oauthHost: "https://www.evernote.com",
|
||||
consumerKey: "Enter your consumer key here",
|
||||
consumerSecret: "Enter your consumer secret here"
|
||||
},
|
||||
tripit: {
|
||||
consumerKey: "a59bb58479f80e24dc6da1b1e61a107db743bc4c",
|
||||
consumerSecret: "41dc4c0c39ac3ab162269a79f399eb180f753c66"
|
||||
},
|
||||
_500px: {
|
||||
consumerKey: "Enter your consumer key here",
|
||||
consumerSecret: "Enter your consumer secret here"
|
||||
},
|
||||
soundcloud: {
|
||||
appId: "79dcfcb876e71dc18c1767b9ebe96298",
|
||||
appSecret: "6f828028dab96838d07b2407cd5f80cd"
|
||||
},
|
||||
mixi: {
|
||||
consumerKey: "Enter your consumer key here",
|
||||
consumerSecret: "Enter your consumer secret here",
|
||||
scope: "r_profile"
|
||||
},
|
||||
mailchimp: {
|
||||
appId: "Enter your client/app id here",
|
||||
appSecret: "Enter your client/app secret here"
|
||||
},
|
||||
mendeley: {
|
||||
consumerKey: "Enter your consumer key here",
|
||||
consumerSecret: "Enter your consumer secret here"
|
||||
}
|
||||
};
|
||||
+17
-34
@@ -1,5 +1,5 @@
|
||||
// Generated by CoffeeScript 1.3.3
|
||||
var MongoStore, ONE_YEAR, app, derby, express, expressApp, gzippo, habitrpgMiddleware, http, path, publicPath, racer, root, server, serverError, store;
|
||||
var MongoStore, ONE_YEAR, app, auth, derby, everyauth, express, expressApp, gzippo, habitrpgMiddleware, http, path, publicPath, racer, root, server, serverError, store;
|
||||
|
||||
http = require('http');
|
||||
|
||||
@@ -13,10 +13,14 @@ derby = require('derby');
|
||||
|
||||
app = require('../app');
|
||||
|
||||
everyauth = require('everyauth');
|
||||
|
||||
serverError = require('./serverError');
|
||||
|
||||
MongoStore = require('connect-mongo')(express);
|
||||
|
||||
auth = require('./auth');
|
||||
|
||||
racer = require('derby/node_modules/racer');
|
||||
|
||||
racer.io.set('transports', ['xhr-polling']);
|
||||
@@ -42,6 +46,10 @@ store = derby.createStore({
|
||||
listen: server
|
||||
});
|
||||
|
||||
auth.setupQueries(store);
|
||||
|
||||
auth.setupEveryauth(everyauth);
|
||||
|
||||
ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
|
||||
|
||||
root = path.dirname(path.dirname(__dirname));
|
||||
@@ -49,24 +57,19 @@ root = path.dirname(path.dirname(__dirname));
|
||||
publicPath = path.join(root, 'public');
|
||||
|
||||
habitrpgMiddleware = function(req, res, next) {
|
||||
var acceptableUid, model, uidParam, _base;
|
||||
var model;
|
||||
model = req.getModel();
|
||||
(_base = req.session).userId || (_base.userId = derby.uuid());
|
||||
uidParam = req.url.split('/')[1];
|
||||
acceptableUid = require('guid').isGuid(uidParam) || (uidParam === '3' || uidParam === '9');
|
||||
if (acceptableUid && req.session.userId !== uidParam) {
|
||||
req.session.userId = uidParam;
|
||||
}
|
||||
model.set('_userId', req.session.userId);
|
||||
model.set('_mobileDevice', /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')));
|
||||
auth.setupPurlAuth(req);
|
||||
auth.setupAccessControl(store);
|
||||
model.set('_stripePubKey', process.env.STRIPE_PUB_KEY);
|
||||
model.set('_nodeEnv', process.env.NODE_ENV);
|
||||
require('./setupStore').accessControl(store);
|
||||
model.set('_mobileDevice', /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')));
|
||||
return next();
|
||||
};
|
||||
|
||||
expressApp.use(express.favicon()).use(gzippo.staticGzip(publicPath, {
|
||||
maxAge: ONE_YEAR
|
||||
})).use(express.compress()).use(express.bodyParser()).use(express.cookieParser()).use(store.sessionMiddleware({
|
||||
})).use(express.compress()).use(express.bodyParser()).use(express.methodOverride()).use(express.cookieParser()).use(store.sessionMiddleware({
|
||||
secret: process.env.SESSION_SECRET || 'YOUR SECRET HERE',
|
||||
cookie: {
|
||||
maxAge: ONE_YEAR
|
||||
@@ -74,26 +77,6 @@ expressApp.use(express.favicon()).use(gzippo.staticGzip(publicPath, {
|
||||
store: new MongoStore({
|
||||
url: process.env.NODE_DB_URI
|
||||
})
|
||||
})).use(store.modelMiddleware()).use(habitrpgMiddleware).use(app.router()).use(expressApp.router).use(serverError(root));
|
||||
})).use(store.modelMiddleware()).use(habitrpgMiddleware).use(everyauth.middleware()).use(app.router()).use(expressApp.router).use(serverError(root));
|
||||
|
||||
require('./api')(expressApp);
|
||||
|
||||
expressApp.post('/', function(req) {
|
||||
return require('../app/reroll').stripeResponse(req);
|
||||
});
|
||||
|
||||
expressApp.get('/privacy', function(req, res) {
|
||||
var staticPages;
|
||||
staticPages = derby.createStatic(root);
|
||||
return staticPages.render('privacy', res);
|
||||
});
|
||||
|
||||
expressApp.get('/terms', function(req, res) {
|
||||
var staticPages;
|
||||
staticPages = derby.createStatic(root);
|
||||
return staticPages.render('terms', res);
|
||||
});
|
||||
|
||||
expressApp.all('*', function(req) {
|
||||
throw "404: " + req.url;
|
||||
});
|
||||
require('./serverRoutes')(expressApp);
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = function(expressApp) {
|
||||
});
|
||||
return res.send(200);
|
||||
});
|
||||
return expressApp.get('/:uid/down/:score?', function(req, res) {
|
||||
expressApp.get('/:uid/down/:score?', function(req, res) {
|
||||
var model, score;
|
||||
score = parseInt(req.params.score) || 1;
|
||||
console.log({
|
||||
@@ -40,4 +40,20 @@ module.exports = function(expressApp) {
|
||||
});
|
||||
return res.send(200);
|
||||
});
|
||||
expressApp.get('/privacy', function(req, res) {
|
||||
var staticPages;
|
||||
staticPages = derby.createStatic(root);
|
||||
return staticPages.render('privacy', res);
|
||||
});
|
||||
expressApp.get('/terms', function(req, res) {
|
||||
var staticPages;
|
||||
staticPages = derby.createStatic(root);
|
||||
return staticPages.render('terms', res);
|
||||
});
|
||||
expressApp.all('*', function(req) {
|
||||
throw "404: " + req.url;
|
||||
});
|
||||
return expressApp.post('/', function(req) {
|
||||
return require('../app/reroll').stripeResponse(req);
|
||||
});
|
||||
};
|
||||
@@ -1,30 +0,0 @@
|
||||
// Generated by CoffeeScript 1.3.3
|
||||
|
||||
module.exports.queries = function(store) {
|
||||
return store.query.expose('users', 'withId', function(id) {
|
||||
return this.byId(id);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.accessControl = function(store) {
|
||||
store.accessControl = true;
|
||||
store.readPathAccess('users.*', function() {
|
||||
var captures, next;
|
||||
if (!(this.session && this.session.userId)) {
|
||||
return;
|
||||
}
|
||||
captures = arguments[0];
|
||||
next = arguments[arguments.length - 1];
|
||||
return next(captures === this.session.userId);
|
||||
});
|
||||
return store.writeAccess('*', 'users.*', function() {
|
||||
var captures, next, pathArray;
|
||||
if (!(this.session && this.session.userId)) {
|
||||
return;
|
||||
}
|
||||
captures = arguments[0];
|
||||
next = arguments[arguments.length - 1];
|
||||
pathArray = captures.split('.');
|
||||
return next(pathArray[0] === this.session.userId);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user