make[1]: Entering directory `/home/travis/build/Tivoli/curio'
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var app, express; |
3 | ||
4 | 1 | express = require('express'); |
5 | ||
6 | 1 | app = express(); |
7 | ||
8 | 1 | module.exports = function(core) { |
9 | 1 | var middleware; |
10 | 1 | middleware = core.get('middleware'); |
11 | 1 | _(middleware).extend(require('./middleware')(app)); |
12 | 1 | app.set('views', "" + __dirname + "/views"); |
13 | 1 | app.set('middleware', middleware); |
14 | 1 | if (app.get('env') === 'development') { |
15 | 0 | app.use(express.logger('dev')); |
16 | 0 | app.use(require('connect-assets')({ |
17 | paths: core.get('assets') | |
18 | })); | |
19 | } else { | |
20 | 1 | app.use(require('connect-assets')({ |
21 | paths: core.get('assets'), | |
22 | build: true | |
23 | })); | |
24 | } | |
25 | 1 | require('./locals')(app, core); |
26 | 1 | require('./routes')(app); |
27 | 1 | return app; |
28 | }; | |
29 | ||
30 | }).call(this); | |
31 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app, core) { |
3 | 1 | app.locals.layout = true; |
4 | 1 | app.locals.env = app.get('env'); |
5 | 1 | app.locals.js = js('admin/bundle'); |
6 | 1 | app.locals.css = css('admin/index'); |
7 | 1 | app.locals.fb = core.get('facebook_config'); |
8 | 1 | return app.locals.google = core.get('google_config'); |
9 | }; | |
10 | ||
11 | }).call(this); | |
12 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app) { |
3 | 1 | var module; |
4 | 1 | module = {}; |
5 | 1 | module.render_index = function(req, res, next) { |
6 | 8 | var cursor, model, root; |
7 | 8 | root = req.route.path.slice(1); |
8 | 8 | model = utils.to_model(root); |
9 | 8 | cursor = model.paginated(req.param('page'), req.param('limit')); |
10 | 8 | return utils.cursorJSON(cursor, function(err, json) { |
11 | 8 | res.locals.collection = json; |
12 | 8 | return res.render("templates/" + root + "/index"); |
13 | }); | |
14 | }; | |
15 | 1 | return module; |
16 | }; | |
17 | ||
18 | }).call(this); | |
19 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | return app.get('/', routes.index); |
8 | }; | |
9 | ||
10 | }).call(this); | |
11 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.index = function(req, res, next) { |
3 | 1 | return res.render('templates/dashboard/index'); |
4 | }; | |
5 | ||
6 | }).call(this); | |
7 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var fs; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | var file, path, _i, _len, _ref, _ref1, _results; |
8 | 1 | mw = app.get('middleware'); |
9 | 1 | app.get('*', mw.restricted); |
10 | 1 | _ref = fs.readdirSync(__dirname); |
11 | 1 | _results = []; |
12 | 1 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
13 | 6 | file = _ref[_i]; |
14 | 6 | path = "" + __dirname + "/" + file; |
15 | 6 | if (!((_ref1 = fs.statSync(path)) != null ? _ref1.isDirectory() : void 0)) { |
16 | 1 | continue; |
17 | } | |
18 | 5 | _results.push(require(path)(app, mw)); |
19 | } | |
20 | 1 | return _results; |
21 | }; | |
22 | ||
23 | }).call(this); | |
24 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app, mw) { |
3 | 1 | return app.get('/pages', mw.render_index); |
4 | }; | |
5 | ||
6 | }).call(this); | |
7 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app, mw) { |
3 | 1 | return app.get('/posts', mw.render_index); |
4 | }; | |
5 | ||
6 | }).call(this); | |
7 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | return app.get('/settings', routes.index); |
8 | }; | |
9 | ||
10 | }).call(this); | |
11 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.index = function(req, res, next) { |
3 | 1 | return async.parallel({ |
4 | website: function(done) { | |
5 | 1 | return SiteConfig.find('website', done); |
6 | } | |
7 | }, function(err, results) { | |
8 | 1 | var k, v; |
9 | 1 | for (k in results) { |
10 | 1 | v = results[k]; |
11 | 1 | res.locals[k] = v.toJSON(); |
12 | } | |
13 | 1 | return res.render('templates/settings/index'); |
14 | }); | |
15 | }; | |
16 | ||
17 | }).call(this); | |
18 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app, mw) { |
3 | 1 | return app.get('/users', mw.render_index); |
4 | }; | |
5 | ||
6 | }).call(this); | |
7 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var app, compiled, express, fs, path; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | express = require('express'); |
7 | ||
8 | 1 | app = express(); |
9 | ||
10 | 1 | path = require('path'); |
11 | ||
12 | 1 | compiled = {}; |
13 | ||
14 | 1 | module.exports = function(core) { |
15 | 1 | var compile; |
16 | 1 | compile = function(type) { |
17 | 2 | var data, directory, file, name, regex, templates, _i, _len, _ref; |
18 | 2 | directory = path.join(core.get('apps'), type, 'views', 'templates'); |
19 | 2 | regex = new RegExp("" + directory + "/(.*).dust$"); |
20 | 2 | templates = []; |
21 | 2 | _ref = utils.walk_dir(directory); |
22 | 2 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
23 | 19 | file = _ref[_i]; |
24 | 19 | if (!(/dust$/.test(file))) { |
25 | 0 | continue; |
26 | } | |
27 | 19 | data = fs.readFileSync(file, 'utf8'); |
28 | 19 | name = file.match(regex)[1]; |
29 | 19 | templates.push(dust.compile(data, "templates/" + name)); |
30 | } | |
31 | 2 | return templates.join(''); |
32 | }; | |
33 | 1 | app.get('/:templates', function(req, res, next) { |
34 | 20 | var type; |
35 | 20 | type = path.basename(req.params.templates, '.js'); |
36 | 20 | res.set('Content-Type', 'application/javascript'); |
37 | 20 | if (compiled[type] == null) { |
38 | 2 | compiled[type] = compile(type); |
39 | } | |
40 | 20 | return res.send(compiled[type]); |
41 | }); | |
42 | 1 | return app; |
43 | }; | |
44 | ||
45 | }).call(this); | |
46 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var app, express; |
3 | ||
4 | 1 | express = require('express'); |
5 | ||
6 | 1 | app = express(); |
7 | ||
8 | 1 | module.exports = function(core) { |
9 | 1 | app.set('aws_config', core.get('aws_config')); |
10 | 1 | app.set('middleware', core.get('middleware')); |
11 | 1 | require('./routes')(app); |
12 | 1 | return app; |
13 | }; | |
14 | ||
15 | }).call(this); | |
16 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var crypto; |
3 | ||
4 | 1 | crypto = require('crypto'); |
5 | ||
6 | 1 | exports.policy = function(aws) { |
7 | 1 | var s3_policy; |
8 | 1 | s3_policy = { |
9 | expiration: moment().add('minutes', 30).toISOString(), | |
10 | conditions: [ | |
11 | { | |
12 | bucket: aws.s3.bucket | |
13 | }, { | |
14 | acl: "public-read" | |
15 | }, { | |
16 | success_action_status: '201' | |
17 | }, ["starts-with", "$key", ""], ["starts-with", "$Content-Type", ""] | |
18 | ] | |
19 | }; | |
20 | 1 | return new Buffer(JSON.stringify(s3_policy)).toString('base64'); |
21 | }; | |
22 | ||
23 | 1 | exports.signature = function(aws, policy) { |
24 | 1 | return crypto.createHmac('sha1', aws.secret).update(policy).digest('base64'); |
25 | }; | |
26 | ||
27 | }).call(this); | |
28 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var gm; |
3 | ||
4 | 1 | gm = require('gm'); |
5 | ||
6 | 1 | exports.resize = function(width, height, stream, out) { |
7 | 2 | return gm(stream).noProfile().resize(width, height, '>').type('TrueColor').stream('jpg').pipe(out); |
8 | }; | |
9 | ||
10 | 1 | exports.crop = function(width, height, stream, out) { |
11 | 1 | return gm(stream).noProfile().gravity('Center').resize(width, height, '^>').crop(width, height).type('TrueColor').stream('jpg').pipe(out); |
12 | }; | |
13 | ||
14 | }).call(this); | |
15 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var cors, images; |
3 | ||
4 | 1 | images = require('./images'); |
5 | ||
6 | 1 | cors = require('./cors'); |
7 | ||
8 | 1 | module.exports = function(app) { |
9 | 1 | var aws, mw; |
10 | 1 | aws = app.get('aws_config'); |
11 | 1 | mw = app.get('middleware'); |
12 | 1 | app.get('/cors', mw.restricted, function(req, res, next) { |
13 | 1 | var json; |
14 | 1 | json = { |
15 | short_id: utils.shortId(), | |
16 | access_key: aws.key, | |
17 | bucket: aws.s3.bucket, | |
18 | policy: cors.policy(aws) | |
19 | }; | |
20 | 1 | json.signature = cors.signature(aws, json.policy); |
21 | 1 | return res.json(json); |
22 | }); | |
23 | 1 | return app.get('/*', function(req, res, next) { |
24 | 4 | var height, stream, width; |
25 | 4 | width = req.param('w'); |
26 | 4 | height = req.param('h'); |
27 | 4 | res.set('Content-Type', 'image/jpg'); |
28 | 4 | res.set('Cache-Control', 'public, max-age=31536000'); |
29 | 4 | res.set('Expires', new Date(Date.now() + 31536000000).toUTCString()); |
30 | 4 | stream = request.get("http://s3.amazonaws.com/" + aws.s3.bucket + "/" + req.params[0]); |
31 | 4 | if (!((width != null) || (height != null))) { |
32 | 1 | return stream.pipe(res); |
33 | } | |
34 | 3 | return images[req.param('m') || 'resize'](width, height, stream, res); |
35 | }); | |
36 | }; | |
37 | ||
38 | }).call(this); | |
39 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var app, express; |
3 | ||
4 | 1 | express = require('express'); |
5 | ||
6 | 1 | app = express(); |
7 | ||
8 | 1 | module.exports = function(core) { |
9 | 1 | var middleware; |
10 | 1 | middleware = core.get('middleware'); |
11 | 1 | _(middleware).extend(require('./middleware')(app)); |
12 | 1 | app.set('views', "" + __dirname + "/views"); |
13 | 1 | app.set('middleware', middleware); |
14 | 1 | if (app.get('env') === 'development') { |
15 | 0 | app.use(express.logger('dev')); |
16 | 0 | app.use(require('connect-assets')({ |
17 | paths: core.get('assets') | |
18 | })); | |
19 | } else { | |
20 | 1 | app.use(require('connect-assets')({ |
21 | paths: core.get('assets'), | |
22 | build: true | |
23 | })); | |
24 | } | |
25 | 1 | require('./locals')(app, core); |
26 | 1 | require('./routes')(app); |
27 | 1 | return app; |
28 | }; | |
29 | ||
30 | }).call(this); | |
31 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app, core) { |
3 | 1 | app.locals.layout = true; |
4 | 1 | app.locals.env = app.get('env'); |
5 | 1 | app.locals.js = js('website/bundle'); |
6 | 1 | app.locals.css = css('website/index'); |
7 | 1 | app.locals.fb = core.get('facebook_config'); |
8 | 1 | return app.locals.google = core.get('google_config'); |
9 | }; | |
10 | ||
11 | }).call(this); | |
12 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app) { |
3 | 1 | var module; |
4 | 1 | module = {}; |
5 | 1 | module.load_locals = function(req, res, next) { |
6 | 81 | if (app.locals.website != null) { |
7 | 78 | return next(); |
8 | } | |
9 | 3 | return SiteConfig.find('website', function(err, config) { |
10 | 3 | if (err != null) { |
11 | 0 | return next(); |
12 | } | |
13 | 3 | app.locals.website = config.toJSON(); |
14 | 3 | return next(); |
15 | }); | |
16 | }; | |
17 | 1 | return module; |
18 | }; | |
19 | ||
20 | }).call(this); | |
21 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app, mw) { |
3 | 1 | var routes; |
4 | 1 | app.param(':config', function(req, res, next, id) { |
5 | 5 | return SiteConfig.find(id, function(err, config) { |
6 | 5 | if (err != null) { |
7 | 0 | return next(err); |
8 | } | |
9 | 5 | req.resource = config; |
10 | 5 | return next(); |
11 | }); | |
12 | }); | |
13 | 1 | routes = require('./routes')(app); |
14 | 1 | app.all('/configs*', mw.restricted); |
15 | 1 | app.get('/configs/:config', mw.read); |
16 | 1 | return app.put('/configs/:config', routes.update); |
17 | }; | |
18 | ||
19 | }).call(this); | |
20 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app) { |
3 | 1 | var routes; |
4 | 1 | routes = { |
5 | update: function(req, res, next) { | |
6 | 2 | if (req.param('config') === 'website') { |
7 | 2 | delete app.locals.website; |
8 | } | |
9 | 2 | return utils.save_and_send(req, res, next); |
10 | } | |
11 | }; | |
12 | 1 | return routes; |
13 | }; | |
14 | ||
15 | }).call(this); | |
16 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var fs; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | module.exports = function(app) { |
7 | 1 | var file, mw, path, _i, _len, _ref, _ref1; |
8 | 1 | mw = app.get('middleware'); |
9 | 1 | app.get(/^((?!png|jpg|js|css|woff|html).)*$/, mw.load_locals, function(req, res, next) { |
10 | 81 | var _ref; |
11 | 81 | res.locals.current_user = (_ref = req.session) != null ? _ref.user : void 0; |
12 | 81 | return next(); |
13 | }); | |
14 | 1 | _ref = fs.readdirSync(__dirname); |
15 | 1 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
16 | 9 | file = _ref[_i]; |
17 | 9 | path = "" + __dirname + "/" + file; |
18 | 9 | if (!((_ref1 = fs.statSync(path)) != null ? _ref1.isDirectory() : void 0)) { |
19 | 1 | continue; |
20 | } | |
21 | 8 | require(path)(app, mw); |
22 | } | |
23 | 1 | app.param(':page_or_post', function(req, res, next, id) { |
24 | 2 | return async.parallel({ |
25 | post: function(done) { | |
26 | 2 | return Post.find(id, function(err, post) { |
27 | 2 | return done(null, post); |
28 | }); | |
29 | }, | |
30 | page: function(done) { | |
31 | 2 | return Page.find(id, function(err, page) { |
32 | 2 | return done(null, page); |
33 | }); | |
34 | } | |
35 | }, function(err, results) { | |
36 | 2 | if (!((results.post != null) || (results.page != null))) { |
37 | 0 | return next(new NotFound('Page not found')); |
38 | } | |
39 | 2 | req.resource = results.page || results.post; |
40 | 2 | return next(); |
41 | }); | |
42 | }); | |
43 | 1 | return app.get('/:page_or_post', mw.read); |
44 | }; | |
45 | ||
46 | }).call(this); | |
47 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | app.param(':source', function(req, res, next, source) { |
8 | 4 | var model; |
9 | 4 | model = global[fleck.capitalize(source)]; |
10 | 4 | return new model(req.body).validate(function(err, source) { |
11 | 4 | if (err != null) { |
12 | 2 | return next(err); |
13 | } | |
14 | 2 | req.source = source; |
15 | 2 | return next(); |
16 | }); | |
17 | }); | |
18 | 1 | return app.post('/oauth/:source', routes.create); |
19 | }; | |
20 | ||
21 | }).call(this); | |
22 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.create = function(req, res, next) { |
3 | 2 | return req.source.find_or_create_user(function(err, source) { |
4 | 2 | if (err != null) { |
5 | 0 | return next(err); |
6 | } | |
7 | 2 | return source.update_user(function(err, source) { |
8 | 2 | var json; |
9 | 2 | if (err != null) { |
10 | 0 | return next(err); |
11 | } | |
12 | 2 | json = source.user.set_self().toJSON(); |
13 | 2 | req.session.user = json; |
14 | 2 | return res.json(json); |
15 | }); | |
16 | }); | |
17 | }; | |
18 | ||
19 | }).call(this); | |
20 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | app.param(':page', function(req, res, next, id) { |
8 | 15 | return Page.find(id, function(err, page) { |
9 | 15 | if (err != null) { |
10 | 2 | return next(err); |
11 | } | |
12 | 13 | req.resource = page; |
13 | 13 | return next(); |
14 | }); | |
15 | }); | |
16 | 1 | app.get('/pages', mw.restricted, mw.get_index); |
17 | 1 | app.post('/pages', mw.restricted, routes.create); |
18 | 1 | app.get('/pages/:page', mw.read); |
19 | 1 | app.put('/pages/:page', mw.restricted, utils.save_and_send); |
20 | 1 | return app["delete"]('/pages/:page', mw.restricted, mw.destroy); |
21 | }; | |
22 | ||
23 | }).call(this); | |
24 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.create = function(req, res, next) { |
3 | 7 | req.resource = new Page(req.body); |
4 | 7 | return utils.save_and_send(req, res, next); |
5 | }; | |
6 | ||
7 | }).call(this); | |
8 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | app.param(':post', function(req, res, next, id) { |
8 | 13 | return Post.find(id, function(err, post) { |
9 | 13 | if (err != null) { |
10 | 2 | return next(err); |
11 | } | |
12 | 11 | req.resource = post; |
13 | 11 | return next(); |
14 | }); | |
15 | }); | |
16 | 1 | app.get('/posts', routes.index); |
17 | 1 | app.post('/posts', mw.restricted, routes.create); |
18 | 1 | app.get('/posts/:post', mw.read); |
19 | 1 | app.put('/posts/:post', mw.restricted, utils.save_and_send); |
20 | 1 | return app["delete"]('/posts/:post', mw.restricted, mw.destroy); |
21 | }; | |
22 | ||
23 | }).call(this); | |
24 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.index = function(req, res, next) { |
3 | 7 | var cursor; |
4 | 7 | cursor = Post.paginated(req.param('page'), req.param('limit')); |
5 | 7 | return utils.streamJSON(req, res, next, cursor); |
6 | }; | |
7 | ||
8 | 1 | exports.create = function(req, res, next) { |
9 | 4 | req.resource = new Post(req.body).set_user(req.session.user.id); |
10 | 4 | return utils.save_and_send(req, res, next); |
11 | }; | |
12 | ||
13 | }).call(this); | |
14 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | return app.get('/search', routes.index); |
8 | }; | |
9 | ||
10 | }).call(this); | |
11 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.index = function(req, res, next) { |
3 | 7 | var cursor, model, query; |
4 | 7 | if (req.query.q == null) { |
5 | 1 | return next(new BadRequest('Missing Query')); |
6 | } | |
7 | 6 | if (req.query.core == null) { |
8 | 1 | return next(new BadRequest('Missing Core')); |
9 | } | |
10 | 5 | model = global[fleck.inflect(req.query.core, 'singularize', 'capitalize')]; |
11 | 5 | query = (function() { |
12 | 5 | switch (req.query.core) { |
13 | case 'users': | |
14 | 2 | return { |
15 | username: new RegExp("" + req.query.q, 'i') | |
16 | }; | |
17 | case 'posts': | |
18 | 3 | return { |
19 | slug: new RegExp(_(req.query.q).toSlug()) | |
20 | }; | |
21 | } | |
22 | })(); | |
23 | 5 | cursor = model.search(query, req.query.page, req.query.limit); |
24 | 5 | return utils.streamJSON(req, res, next, cursor); |
25 | }; | |
26 | ||
27 | }).call(this); | |
28 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | app.post('/sessions', routes.create); |
8 | 1 | app.get('/sessions/token', routes.token); |
9 | 1 | return app.get('/logout', mw.authed, routes.destroy); |
10 | }; | |
11 | ||
12 | }).call(this); | |
13 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.create = function(req, res, next) { |
3 | 13 | var _ref; |
4 | 13 | if (((_ref = req.session) != null ? _ref.user : void 0) != null) { |
5 | 0 | return next(); |
6 | } | |
7 | 13 | return User.authenticate(req.body.email, req.body.password, function(err, user) { |
8 | 13 | var json; |
9 | 13 | if (err != null) { |
10 | 6 | return next(err); |
11 | } | |
12 | 7 | json = req.session.user = user.toJSON(); |
13 | 7 | return res.json(json); |
14 | }); | |
15 | }; | |
16 | ||
17 | 1 | exports.destroy = function(req, res) { |
18 | 1 | return req.session.destroy(function() { |
19 | 1 | var back; |
20 | 1 | back = req.get('referer') || '/'; |
21 | 1 | return res.redirect(back); |
22 | }); | |
23 | }; | |
24 | ||
25 | 1 | exports.token = function(req, res, next) { |
26 | 3 | return User.find_by_token(req.query.token, function(err, user) { |
27 | 3 | if (err != null) { |
28 | 2 | return next(err); |
29 | } | |
30 | 1 | req.session.user = user.set_self().toJSON(); |
31 | 1 | return res.redirect('/'); |
32 | }); | |
33 | }; | |
34 | ||
35 | }).call(this); | |
36 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | return app.get('/', routes.index); |
8 | }; | |
9 | ||
10 | }).call(this); | |
11 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.index = function(req, res, next) { |
3 | 9 | return res.render('templates/home/index'); |
4 | }; | |
5 | ||
6 | }).call(this); | |
7 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var routes; |
3 | ||
4 | 1 | routes = require('./routes'); |
5 | ||
6 | 1 | module.exports = function(app, mw) { |
7 | 1 | app.param(':user', function(req, res, next, id) { |
8 | 26 | return User.find(id, function(err, user) { |
9 | 26 | var _ref, _ref1; |
10 | 26 | if (err != null) { |
11 | 1 | return next(err); |
12 | } | |
13 | 25 | req.resource = user; |
14 | 25 | if (req.resource.id() === ((_ref = req.session) != null ? (_ref1 = _ref.user) != null ? _ref1.id : void 0 : void 0)) { |
15 | 11 | req.resource.set_self(); |
16 | } | |
17 | 25 | return next(); |
18 | }); | |
19 | }); | |
20 | 1 | app.get('/users', mw.restricted, routes.index); |
21 | 1 | app.post('/users', routes.create); |
22 | 1 | app.get('/users/me', mw.authed, routes.me); |
23 | 1 | app.post('/users/resetpassword', routes.resetpassword); |
24 | 1 | app.get('/users/:user', mw.read); |
25 | 1 | app.put('/users/:user', mw["private"], routes.update); |
26 | 1 | return app.all('/users/:user/roles', mw.restricted, routes.update_role); |
27 | }; | |
28 | ||
29 | }).call(this); | |
30 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | exports.index = function(req, res, next) { |
3 | 6 | var cursor; |
4 | 6 | cursor = User.paginated(req.query.page, req.query.limit); |
5 | 6 | return utils.streamJSON(req, res, next, cursor); |
6 | }; | |
7 | ||
8 | 1 | exports.create = function(req, res, next) { |
9 | 12 | req.resource = new User(req.body).set_self(); |
10 | 12 | req.resource.once('saved', function() { |
11 | 2 | return req.session.user = req.resource.toJSON(); |
12 | }); | |
13 | 12 | return utils.save_and_send(req, res, next); |
14 | }; | |
15 | ||
16 | 1 | exports.me = function(req, res, next) { |
17 | 17 | return res.json(req.session.user); |
18 | }; | |
19 | ||
20 | 1 | exports.update = function(req, res, next) { |
21 | 11 | req.resource.once('saved', function() { |
22 | 6 | return req.session.user = req.resource.toJSON(); |
23 | }); | |
24 | 11 | return utils.save_and_send(req, res, next); |
25 | }; | |
26 | ||
27 | 1 | exports.resetpassword = function(req, res, next) { |
28 | 4 | if (!_(req.body.email).isEmail()) { |
29 | 2 | return next(new BadRequest('Missing or Invalid Email')); |
30 | } | |
31 | 2 | return User.find(req.body.email, function(err, user) { |
32 | 2 | if (err != null) { |
33 | 1 | return next(err); |
34 | } | |
35 | 1 | return user.update_token(function(err, token) { |
36 | 1 | if (err != null) { |
37 | 0 | return next(err); |
38 | } | |
39 | 1 | return res.send(200); |
40 | }); | |
41 | }); | |
42 | }; | |
43 | ||
44 | 1 | exports.update_role = function(req, res, next) { |
45 | 7 | var method; |
46 | 7 | method = req.method === 'POST' ? 'add' : 'remove'; |
47 | 7 | return req.resource.update_role(method, req.body.role, function(err, user) { |
48 | 7 | if (err != null) { |
49 | 1 | return next(err); |
50 | } | |
51 | 6 | return res.json(user.toJSON()); |
52 | }); | |
53 | }; | |
54 | ||
55 | }).call(this); | |
56 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var fs; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | module.exports = function(app) { |
7 | 1 | var config, file, json, name, _i, _len, _ref, _results; |
8 | 1 | _ref = fs.readdirSync(__dirname); |
9 | 1 | _results = []; |
10 | 1 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
11 | 5 | file = _ref[_i]; |
12 | 5 | if (!(/\.json$/.test(file))) { |
13 | 1 | continue; |
14 | } | |
15 | 4 | name = file.replace('.json', ''); |
16 | 4 | json = require("/home/travis/build/Tivoli/curio/server/configs/./" + name); |
17 | 4 | config = _.extend({}, json.defaults, json[app.get('env')]); |
18 | 4 | _results.push(app.set("" + name + "_config", config)); |
19 | } | |
20 | 1 | return _results; |
21 | }; | |
22 | ||
23 | }).call(this); | |
24 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var __hasProp = {}.hasOwnProperty, |
3 | 52 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
4 | ||
5 | 1 | global.BadRequest = (function(_super) { |
6 | 1 | __extends(BadRequest, _super); |
7 | ||
8 | 1 | function BadRequest(message) { |
9 | 32 | this.message = message; |
10 | 32 | this.statusCode = 400; |
11 | 32 | BadRequest.__super__.constructor.call(this); |
12 | } | |
13 | ||
14 | 1 | return BadRequest; |
15 | ||
16 | })(Error); | |
17 | ||
18 | 1 | global.Unauthorized = (function(_super) { |
19 | 1 | __extends(Unauthorized, _super); |
20 | ||
21 | 1 | function Unauthorized() { |
22 | 39 | this.statusCode = 401; |
23 | 39 | this.message = 'Unauthorized'; |
24 | 39 | Unauthorized.__super__.constructor.call(this); |
25 | } | |
26 | ||
27 | 1 | return Unauthorized; |
28 | ||
29 | })(Error); | |
30 | ||
31 | 1 | global.NotFound = (function(_super) { |
32 | 1 | __extends(NotFound, _super); |
33 | ||
34 | 1 | function NotFound(message) { |
35 | 10 | this.message = message; |
36 | 10 | this.statusCode = 404; |
37 | 10 | NotFound.__super__.constructor.call(this); |
38 | } | |
39 | ||
40 | 1 | return NotFound; |
41 | ||
42 | })(Error); | |
43 | ||
44 | 1 | global.MongoError = (function(_super) { |
45 | 1 | __extends(MongoError, _super); |
46 | ||
47 | 1 | function MongoError(message) { |
48 | 0 | this.message = message; |
49 | 0 | this.statusCode = 500; |
50 | 0 | MongoError.__super__.constructor.call(this); |
51 | } | |
52 | ||
53 | 1 | return MongoError; |
54 | ||
55 | })(Error); | |
56 | ||
57 | }).call(this); | |
58 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var MongoStore, app, assets, blue, cons, express, mongo, red, reset, |
3 | 0 | __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
4 | ||
5 | 1 | express = require('express'); |
6 | ||
7 | 1 | app = express(); |
8 | ||
9 | 1 | cons = require('consolidate'); |
10 | ||
11 | 1 | blue = '\u001b[34m'; |
12 | ||
13 | 1 | red = '\u001b[31m'; |
14 | ||
15 | 1 | reset = '\u001b[0m'; |
16 | ||
17 | 1 | assets = ["" + __dirname + "/assets/js", "" + __dirname + "/shared", "" + __dirname + "/assets/css"]; |
18 | ||
19 | 1 | global._ = require('underscore'); |
20 | ||
21 | 1 | global.async = require('async'); |
22 | ||
23 | 1 | global.fleck = require('fleck'); |
24 | ||
25 | 1 | global.moment = require('moment'); |
26 | ||
27 | 1 | global.request = require('request').defaults({ |
28 | _json: true | |
29 | }); | |
30 | ||
31 | 1 | global.dust = require('dustjs-linkedin'); |
32 | ||
33 | 1 | require('dustjs-helpers'); |
34 | ||
35 | 1 | global.utils = require('./utilities')(app); |
36 | ||
37 | 1 | utils.load_shared("" + __dirname + "/shared"); |
38 | ||
39 | 1 | require('./errors'); |
40 | ||
41 | 1 | require('./configs')(app); |
42 | ||
43 | 1 | mongo = require('./mongo')(app); |
44 | ||
45 | 1 | MongoStore = require('connect-mongo')(express); |
46 | ||
47 | 1 | app.engine('dust', cons.dust); |
48 | ||
49 | 1 | app.set('port', process.env.PORT || 3000); |
50 | ||
51 | 1 | app.set('version', require('../package').version); |
52 | ||
53 | 1 | app.set('description', require('../package').description); |
54 | ||
55 | 1 | app.set('views', "" + __dirname + "/views"); |
56 | ||
57 | 1 | app.set('view engine', 'dust'); |
58 | ||
59 | 1 | app.set('apps', "" + __dirname + "/apps"); |
60 | ||
61 | 1 | app.set('assets', assets); |
62 | ||
63 | 1 | app.set('middleware', require('./middleware')(app)); |
64 | ||
65 | 1 | app.use(express.favicon("" + __dirname + "/public/favicon.png", { |
66 | maxAge: 2592000000 | |
67 | })); | |
68 | ||
69 | 1 | app.use(express.compress()); |
70 | ||
71 | 1 | app.use(express.methodOverride()); |
72 | ||
73 | 1 | app.use(express.urlencoded()); |
74 | ||
75 | 1 | app.use(express.json()); |
76 | ||
77 | 1 | app.use(express.cookieParser()); |
78 | ||
79 | 1 | mongo.on('open', function() { |
80 | 1 | var server; |
81 | 1 | app.use(express.session({ |
82 | secret: 'curio cookie', | |
83 | cookie: { | |
84 | maxAge: 604800000 | |
85 | }, | |
86 | store: new MongoStore({ | |
87 | db: mongo._db | |
88 | }) | |
89 | })); | |
90 | 1 | app.use('/templates', require('./apps/templates')(app)); |
91 | 1 | app.use('/uploads', require('./apps/uploads')(app)); |
92 | 1 | app.use('/admin', require('./apps/admin')(app)); |
93 | 1 | app.use('/', require('./apps/website')(app)); |
94 | 1 | app.use(app.get('middleware').error); |
95 | 1 | if (app.get('env') === 'development') { |
96 | 0 | app.use(express.logger('dev')); |
97 | 0 | app.use(express["static"]("" + __dirname + "/public")); |
98 | } else { | |
99 | 1 | app.use(express["static"]("" + __dirname + "/public", { |
100 | maxAge: 86400000 | |
101 | })); | |
102 | } | |
103 | 1 | if (__indexOf.call(process.argv, '--seed') < 0) { |
104 | 1 | server = require('http').createServer(app); |
105 | 1 | server.listen(app.get("port"), function() { |
106 | 1 | var timestamp; |
107 | 1 | if (!process.env.NODE_COV) { |
108 | 0 | timestamp = moment().format('D MMM H:mm:ss'); |
109 | 0 | return console.log("%s - %s v%s (" + blue + "%s" + reset + ") port " + red + "%d" + reset, timestamp, app.get('description'), app.get('version'), app.get('env'), app.get('port')); |
110 | } | |
111 | }); | |
112 | } | |
113 | 1 | return process.on('SIGINT', function() { |
114 | 0 | async.series({ |
115 | mongo: function(done) { | |
116 | 0 | return app.mongo.db.close(done); |
117 | }, | |
118 | server: function(done) { | |
119 | 0 | return server.close(done); |
120 | } | |
121 | }, function(err, results) { | |
122 | 0 | return process.exit(0); |
123 | }); | |
124 | 0 | return setTimeout(function() { |
125 | 0 | console.error("Forcefully shutting down"); |
126 | 0 | return process.exit(1); |
127 | }, 30 * 1000); | |
128 | }); | |
129 | }); | |
130 | ||
131 | 1 | module.exports = app; |
132 | ||
133 | }).call(this); | |
134 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var bugsnag; |
3 | ||
4 | 1 | bugsnag = require('bugsnag'); |
5 | ||
6 | 1 | module.exports = function(app) { |
7 | 1 | var module; |
8 | 1 | module = {}; |
9 | 1 | bugsnag.register(app.get('bugsnag_config').key); |
10 | 1 | module.authed = function(req, res, next) { |
11 | 25 | var _ref; |
12 | 25 | if (((_ref = req.session) != null ? _ref.user : void 0) != null) { |
13 | 18 | return next(); |
14 | } | |
15 | 7 | return next(new Unauthorized); |
16 | }; | |
17 | 1 | module["private"] = function(req, res, next) { |
18 | 13 | var _ref, _ref1, _ref2, _ref3; |
19 | 13 | if (((_ref = req.session) != null ? (_ref1 = _ref.user) != null ? _ref1.id : void 0 : void 0) === req.resource.id()) { |
20 | 10 | return next(); |
21 | } | |
22 | 3 | if ((_ref2 = req.session) != null ? (_ref3 = _ref2.user) != null ? _ref3.is_admin : void 0 : void 0) { |
23 | 1 | return next(); |
24 | } | |
25 | 2 | return next(new Unauthorized); |
26 | }; | |
27 | 1 | module.restricted = function(req, res, next) { |
28 | 77 | var _ref, _ref1; |
29 | 77 | if ((_ref = req.session) != null ? (_ref1 = _ref.user) != null ? _ref1.is_admin : void 0 : void 0) { |
30 | 55 | return next(); |
31 | } | |
32 | 22 | return next(new Unauthorized); |
33 | }; | |
34 | 1 | module.read = function(req, res) { |
35 | 12 | var json, name, root; |
36 | 12 | name = req.resource.constructor.name; |
37 | 12 | root = fleck.pluralize(name).toLowerCase(); |
38 | 12 | json = req.resource.toJSON(); |
39 | 12 | return res.format({ |
40 | html: function() { | |
41 | 2 | return res.render("templates/" + root + "/show", json); |
42 | }, | |
43 | json: function() { | |
44 | 10 | return res.json(json); |
45 | } | |
46 | }); | |
47 | }; | |
48 | 1 | module.get_index = function(req, res, next) { |
49 | 3 | var cursor, model; |
50 | 3 | if (!utils.is_json_request(req)) { |
51 | 0 | return next(); |
52 | } | |
53 | 3 | model = utils.to_model(req.route.path.slice(1)); |
54 | 3 | cursor = model.paginated(req.param('page'), req.param('limit')); |
55 | 3 | return utils.streamJSON(req, res, next, cursor); |
56 | }; | |
57 | 1 | module.destroy = function(req, res, next) { |
58 | 2 | return req.resource.destroy(function(err) { |
59 | 2 | if (err) { |
60 | 0 | return next(err); |
61 | } | |
62 | 2 | return res.send(200); |
63 | }); | |
64 | }; | |
65 | 1 | module.error = function(err, req, res, next) { |
66 | 74 | var _ref; |
67 | 74 | if ((err.statusCode == null) || /^5\d+/.test(err.statusCode)) { |
68 | 0 | if ((_ref = app.get('env')) !== 'development' && _ref !== 'test') { |
69 | 0 | bugsnag.notify(err); |
70 | } | |
71 | } | |
72 | 74 | return res.format({ |
73 | html: function() { | |
74 | 2 | if (err.statusCode === 401) { |
75 | 2 | return res.redirect('/'); |
76 | } | |
77 | 0 | return res.status(err.statusCode || 500).render("error", { |
78 | url: req.url, | |
79 | error: err.message | |
80 | }); | |
81 | }, | |
82 | json: function() { | |
83 | 72 | return res.json(err.statusCode || 500, { |
84 | url: req.url, | |
85 | error: err.message | |
86 | }); | |
87 | } | |
88 | }); | |
89 | }; | |
90 | 1 | return module; |
91 | }; | |
92 | ||
93 | }).call(this); | |
94 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app) { |
3 | 1 | var mongo; |
4 | 1 | mongo = app.mongo; |
5 | 1 | mongo.configs = mongo.db.collection('configs'); |
6 | 1 | mongo.users = mongo.db.collection('users'); |
7 | 1 | mongo.users.ensureIndex('username', { |
8 | unique: true | |
9 | }, function() {}); | |
10 | 1 | mongo.users.ensureIndex('email', { |
11 | unique: true | |
12 | }, function() {}); | |
13 | 1 | mongo.posts = mongo.db.collection('posts'); |
14 | 1 | mongo.posts.ensureIndex('slug', { |
15 | unique: true | |
16 | }, function() {}); | |
17 | 1 | mongo.pages = mongo.db.collection('pages'); |
18 | 1 | mongo.pages.ensureIndex('path', { |
19 | unique: true | |
20 | }, function() {}); | |
21 | 1 | mongo.pages.ensureIndex('title', { |
22 | unique: true | |
23 | }, function() {}); | |
24 | 1 | mongo.tokens = mongo.db.collection('tokens'); |
25 | 1 | return mongo.tokens.ensureIndex({ |
26 | expires: 1 | |
27 | }, { | |
28 | expireAfterSeconds: 86400 * 2 | |
29 | }, function() {}); | |
30 | }; | |
31 | ||
32 | }).call(this); | |
33 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var MongoClient, ObjectID, mongodb, |
3 | 0 | __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
4 | ||
5 | 1 | mongodb = require('mongodb'); |
6 | ||
7 | 1 | MongoClient = mongodb.MongoClient; |
8 | ||
9 | 1 | ObjectID = mongodb.ObjectID; |
10 | ||
11 | 1 | module.exports = function(app) { |
12 | 1 | var client, config, seed; |
13 | 1 | config = app.get('mongo_config'); |
14 | 1 | seed = require('./seed')(app); |
15 | 1 | app.mongo = { |
16 | ObjectID: ObjectID, | |
17 | seed: seed.seed, | |
18 | seed_dir: seed.dir, | |
19 | stringToID: function(id) { | |
20 | 285 | var err; |
21 | 285 | if (id instanceof ObjectID) { |
22 | 230 | return id; |
23 | } | |
24 | 55 | try { |
25 | 55 | return new ObjectID.createFromHexString(id); |
26 | } catch (_error) { | |
27 | 2 | err = _error; |
28 | 2 | return id; |
29 | } | |
30 | }, | |
31 | dateToID: function(date) { | |
32 | 2 | date = (function() { |
33 | 2 | switch (true) { |
34 | case _(date).isDate(): | |
35 | 1 | return Math.floor(date / 1000); |
36 | default: | |
37 | 1 | return Math.floor(new Date(parseInt(date)) / 1000); |
38 | } | |
39 | })(); | |
40 | 2 | return new ObjectID.createFromTime(date); |
41 | } | |
42 | }; | |
43 | 1 | client = new MongoClient(); |
44 | 1 | client.connect(config.url, config.options, function(err, _db) { |
45 | 1 | if (err != null) { |
46 | 0 | throw new MongoError(err.message); |
47 | } | |
48 | 1 | app.mongo.db = _db; |
49 | 1 | require('./collections')(app); |
50 | 1 | require('./lib')(app); |
51 | 1 | require('./models')(app); |
52 | 1 | if (__indexOf.call(process.argv, '--seed') >= 0) { |
53 | 0 | if (app.get('env') !== 'development') { |
54 | 0 | return process.exit(0); |
55 | } | |
56 | 0 | console.log('=== Seeding local database ==='); |
57 | 0 | return app.mongo.seed(function() { |
58 | 0 | return process.exit(0); |
59 | }); | |
60 | } | |
61 | }); | |
62 | 1 | return client; |
63 | }; | |
64 | ||
65 | }).call(this); | |
66 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var fs; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | module.exports = function(app) { |
7 | 1 | var file, _i, _len, _ref, _results; |
8 | 1 | _ref = fs.readdirSync(__dirname); |
9 | 1 | _results = []; |
10 | 1 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
11 | 3 | file = _ref[_i]; |
12 | 3 | if (/^((?!index).)*$/.test(file)) { |
13 | 2 | _results.push(require("/home/travis/build/Tivoli/curio/server/mongo/lib/./" + file)(app)); |
14 | } | |
15 | } | |
16 | 1 | return _results; |
17 | }; | |
18 | ||
19 | }).call(this); | |
20 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var EventEmitter, |
3 | __hasProp = {}.hasOwnProperty, | |
4 | 9 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
5 | ||
6 | 1 | EventEmitter = require("events").EventEmitter; |
7 | ||
8 | 1 | module.exports = function(app) { |
9 | 1 | var mongo; |
10 | 1 | mongo = app.mongo; |
11 | 1 | return global.Model = (function(_super) { |
12 | 1 | __extends(Model, _super); |
13 | ||
14 | 1 | Model.strToID = function(id) { |
15 | 285 | return mongo.stringToID(id); |
16 | }; | |
17 | ||
18 | 1 | Model.dateToID = function(date) { |
19 | 2 | return mongo.dateToID(date); |
20 | }; | |
21 | ||
22 | 1 | Model.order_by = [['_id', 'desc']]; |
23 | ||
24 | 1 | Model.find = function(id, fn) { |
25 | 302 | var query; |
26 | 302 | query = { |
27 | $or: [] | |
28 | }; | |
29 | 302 | if (_(id).isObjectID()) { |
30 | 276 | query.$or.push({ |
31 | _id: this.strToID(id) | |
32 | }); | |
33 | } | |
34 | 302 | if (_(id != null ? typeof id.toLowerCase === "function" ? id.toLowerCase() : void 0 : void 0).isSlug()) { |
35 | 59 | query.$or.push({ |
36 | slug: id.toLowerCase() | |
37 | }); | |
38 | } | |
39 | 302 | if (_(id != null ? typeof id.toLowerCase === "function" ? id.toLowerCase() : void 0 : void 0).isEmail()) { |
40 | 12 | query.$or.push({ |
41 | email: id.toLowerCase() | |
42 | }); | |
43 | } | |
44 | 302 | if (_(id != null ? typeof id.toLowerCase === "function" ? id.toLowerCase() : void 0 : void 0).isUsername()) { |
45 | 12 | query.$or.push({ |
46 | username: id.toLowerCase() | |
47 | }); | |
48 | } | |
49 | 302 | if (_(id).isString() && this.name === 'Page') { |
50 | 17 | query.$or.push({ |
51 | path: id.toLowerCase() | |
52 | }); | |
53 | } | |
54 | 302 | if (!query.$or.length) { |
55 | 2 | return fn(new BadRequest("Missing query param for " + this.name)); |
56 | } | |
57 | 300 | return this.collection.findOne(query, (function(_this) { |
58 | 300 | return function(err, data) { |
59 | 300 | if (data == null) { |
60 | 9 | return fn(err || new NotFound("Cannot find " + _this.name)); |
61 | } | |
62 | 291 | return new global[_this.name](data).populate(fn); |
63 | }; | |
64 | })(this)); | |
65 | }; | |
66 | ||
67 | 1 | Model.paginated = function(page, limit) { |
68 | 24 | var opts; |
69 | 24 | if (page == null) { |
70 | 20 | page = 1; |
71 | } | |
72 | 24 | if (limit == null) { |
73 | 20 | limit = 20; |
74 | } | |
75 | 24 | opts = { |
76 | skip: (+page - 1) * limit, | |
77 | limit: limit | |
78 | }; | |
79 | 24 | return this.collection.find({}, opts).sort(this.order_by); |
80 | }; | |
81 | ||
82 | 1 | Model.search = function(query, page, limit) { |
83 | 5 | var opts; |
84 | 5 | if (page == null) { |
85 | 5 | page = 1; |
86 | } | |
87 | 5 | if (limit == null) { |
88 | 5 | limit = 20; |
89 | } | |
90 | 5 | opts = { |
91 | skip: (+page - 1) * limit, | |
92 | limit: limit | |
93 | }; | |
94 | 5 | return this.collection.find(query, opts); |
95 | }; | |
96 | ||
97 | 1 | function Model(model) { |
98 | 814 | var k, v; |
99 | 814 | this.model = model != null ? model : {}; |
100 | 814 | this.strToID = Model.strToID; |
101 | 814 | this.dateToID = Model.dateToID; |
102 | 814 | this.collection = this.constructor.collection; |
103 | 814 | if (this._id() == null) { |
104 | 25 | if (typeof this.defaults === "function") { |
105 | 13 | this.defaults(); |
106 | } | |
107 | } | |
108 | 814 | for (k in this) { |
109 | 30355 | v = this[k]; |
110 | 30355 | if (/^populate_/.test(k)) { |
111 | 814 | this[k] = _(this[k]).bind(this); |
112 | } | |
113 | } | |
114 | 814 | return this; |
115 | } | |
116 | ||
117 | 1 | Model.prototype._id = function() { |
118 | 1078 | return this.model._id; |
119 | }; | |
120 | ||
121 | 1 | Model.prototype.id = function() { |
122 | 801 | var _ref; |
123 | 801 | return (_ref = this.model._id) != null ? _ref.toHexString() : void 0; |
124 | }; | |
125 | ||
126 | 1 | Model.prototype.slug = function() { |
127 | 223 | return this.model.slug; |
128 | }; | |
129 | ||
130 | 1 | Model.prototype.created_at = function() { |
131 | 223 | return new Date(this._id().getTimestamp()).toISOString(); |
132 | }; | |
133 | ||
134 | 1 | Model.prototype.validate = function(fn) { |
135 | 2 | return fn(null, this); |
136 | }; | |
137 | ||
138 | 1 | Model.prototype.amend = function(values) { |
139 | 46 | if (this.whitelist != null) { |
140 | 44 | values = _(values).pick(this.whitelist); |
141 | } | |
142 | 46 | if (this.blacklist != null) { |
143 | 2 | values = _(values).omit(this.blacklist); |
144 | } | |
145 | 46 | return this.set(values); |
146 | }; | |
147 | ||
148 | 1 | Model.prototype.set = function(values) { |
149 | 102 | var key, val; |
150 | 102 | if (values == null) { |
151 | 0 | values = {}; |
152 | } | |
153 | 102 | for (key in values) { |
154 | 265 | val = values[key]; |
155 | 265 | this.model[key] = val; |
156 | } | |
157 | 102 | return this; |
158 | }; | |
159 | ||
160 | 1 | Model.prototype.set_user = function(id) { |
161 | 5 | return this.set({ |
162 | _user: this.strToID(id) | |
163 | }); | |
164 | }; | |
165 | ||
166 | 1 | Model.prototype.populate_user = function(fn) { |
167 | 228 | return User.find(this._user(), fn); |
168 | }; | |
169 | ||
170 | 1 | Model.prototype.populate = function(fn) { |
171 | 796 | var field, funcs, k, v, _ref; |
172 | 796 | funcs = {}; |
173 | 796 | _ref = this.model; |
174 | 796 | for (k in _ref) { |
175 | 5166 | v = _ref[k]; |
176 | 5166 | if (!(/^_(?!id)/.test(k))) { |
177 | 4938 | continue; |
178 | } | |
179 | 228 | field = k.slice(1); |
180 | 228 | funcs[field] = this["populate_" + field]; |
181 | } | |
182 | 796 | return async.parallel(funcs, (function(_this) { |
183 | 796 | return function(err, results) { |
184 | 796 | _(_this).extend(results); |
185 | 796 | return fn(null, _this); |
186 | }; | |
187 | })(this)); | |
188 | }; | |
189 | ||
190 | 1 | Model.prototype.save = function(fn) { |
191 | 32 | return this.collection.save(this.model, { |
192 | safe: true | |
193 | }, (function(_this) { | |
194 | 32 | return function(err, model) { |
195 | 32 | var key; |
196 | 32 | if ((err != null) && /^E11000 duplicate key/.test(err.message)) { |
197 | 4 | key = _(/\$(.*?)_/.exec(err.message)).last(); |
198 | 4 | err = new BadRequest("Duplicate " + (fleck.capitalize(key))); |
199 | } | |
200 | 32 | if (err != null) { |
201 | 4 | return typeof fn === "function" ? fn(err) : void 0; |
202 | } | |
203 | 28 | _this.emit('saved'); |
204 | 28 | return typeof fn === "function" ? fn(null, _this) : void 0; |
205 | }; | |
206 | })(this)); | |
207 | }; | |
208 | ||
209 | 1 | Model.prototype.update = function(query, fn) { |
210 | 6 | return this.collection.findAndModify({ |
211 | _id: this._id() | |
212 | }, [], query, { | |
213 | "new": true | |
214 | }, (function(_this) { | |
215 | 6 | return function(err, model) { |
216 | 6 | if (err != null) { |
217 | 0 | return typeof fn === "function" ? fn(err) : void 0; |
218 | } | |
219 | 6 | _this.model = model; |
220 | 6 | return typeof fn === "function" ? fn(null, _this) : void 0; |
221 | }; | |
222 | })(this)); | |
223 | }; | |
224 | ||
225 | 1 | Model.prototype.destroy = function(fn) { |
226 | 2 | return this.collection.remove({ |
227 | _id: this._id() | |
228 | }, (function(_this) { | |
229 | 2 | return function(err, model) { |
230 | 2 | return typeof fn === "function" ? fn(err, _this) : void 0; |
231 | }; | |
232 | })(this)); | |
233 | }; | |
234 | ||
235 | 1 | return Model; |
236 | ||
237 | })(EventEmitter); | |
238 | }; | |
239 | ||
240 | }).call(this); | |
241 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | module.exports = function(app) { |
3 | 1 | return global.SocialModel = (function() { |
4 | 1 | function SocialModel(model) { |
5 | 4 | var _ref, _ref1; |
6 | 4 | this.model = model != null ? model : {}; |
7 | 4 | this.model.uid = (_ref = this.model) != null ? (_ref1 = _ref.uid) != null ? _ref1.toString() : void 0 : void 0; |
8 | 4 | this.model.source = this.constructor.name.toLowerCase(); |
9 | 4 | return this; |
10 | } | |
11 | ||
12 | 1 | SocialModel.prototype.uid = function() { |
13 | 9 | var _ref; |
14 | 9 | return (_ref = this.model) != null ? _ref.uid : void 0; |
15 | }; | |
16 | ||
17 | 1 | SocialModel.prototype.token = function() { |
18 | 6 | var _ref; |
19 | 6 | return (_ref = this.model) != null ? _ref.token : void 0; |
20 | }; | |
21 | ||
22 | 1 | SocialModel.prototype.secret = function() { |
23 | 0 | var _ref; |
24 | 0 | return (_ref = this.model) != null ? _ref.secret : void 0; |
25 | }; | |
26 | ||
27 | 1 | SocialModel.prototype.name = function() { |
28 | 2 | var _ref; |
29 | 2 | return (_ref = this.model) != null ? _ref.name : void 0; |
30 | }; | |
31 | ||
32 | 1 | SocialModel.prototype.avatar = function() { |
33 | 1 | var _ref; |
34 | 1 | return (_ref = this.model) != null ? _ref.avatar : void 0; |
35 | }; | |
36 | ||
37 | 1 | SocialModel.prototype.email = function() { |
38 | 3 | var _ref; |
39 | 3 | return (_ref = this.model) != null ? _ref.email : void 0; |
40 | }; | |
41 | ||
42 | 1 | SocialModel.prototype.gender = function() { |
43 | 4 | var _ref; |
44 | 4 | return (_ref = this.model) != null ? _ref.gender : void 0; |
45 | }; | |
46 | ||
47 | 1 | SocialModel.prototype.source = function() { |
48 | 7 | var _ref; |
49 | 7 | return (_ref = this.model) != null ? _ref.source : void 0; |
50 | }; | |
51 | ||
52 | 1 | SocialModel.prototype.username = function() { |
53 | 1 | var _ref; |
54 | 1 | return (_ref = this.model) != null ? _ref.username : void 0; |
55 | }; | |
56 | ||
57 | 1 | SocialModel.prototype.find_or_create_user = function(fn) { |
58 | 2 | return User.find_by_auth(this.source(), this.uid(), (function(_this) { |
59 | 2 | return function(err, user) { |
60 | 2 | _this.user = user; |
61 | 2 | if (_this.user != null) { |
62 | 1 | return fn(null, _this); |
63 | } | |
64 | 1 | return _this.fetch(function(err, self) { |
65 | 1 | if (_this.email() == null) { |
66 | 0 | return fn(new NotFound('Cannot find user')); |
67 | } | |
68 | 1 | return User.find(_this.email(), function(err, user) { |
69 | 1 | _this.user = user; |
70 | 1 | if (_this.user != null) { |
71 | 0 | return fn(null, _this); |
72 | } | |
73 | 1 | return _this.create_user(fn); |
74 | }); | |
75 | }); | |
76 | }; | |
77 | })(this)); | |
78 | }; | |
79 | ||
80 | 1 | SocialModel.prototype.update_user = function(fn) { |
81 | 2 | return this.fetch((function(_this) { |
82 | 2 | return function(err, model) { |
83 | 2 | var current, updates; |
84 | 2 | if (err != null) { |
85 | 0 | return fn(err); |
86 | } | |
87 | 2 | current = _(_this.user.authentications()).reject(function(a) { |
88 | 1 | return a.source === _this.source(); |
89 | }); | |
90 | 2 | current.push(_this.model); |
91 | 2 | updates = { |
92 | authentications: current | |
93 | }; | |
94 | 2 | if (_this.user.name() == null) { |
95 | 0 | updates.name = _this.name(); |
96 | } | |
97 | 2 | if (_this.user.model.avatar == null) { |
98 | 1 | updates.avatar = _this.avatar(); |
99 | } | |
100 | 2 | if (_this.gender() != null) { |
101 | 2 | updates.gender = _this.gender(); |
102 | } | |
103 | 2 | if (!_this.user.settings()["share_" + (_this.source())]) { |
104 | 2 | updates.settings = _this.user.settings(); |
105 | 2 | updates.settings["share_" + (_this.source())] = 0; |
106 | } | |
107 | 2 | return _this.user.set(updates).save(function(err, user) { |
108 | 2 | if (err != null) { |
109 | 0 | return fn(err); |
110 | } | |
111 | 2 | _this.user = user; |
112 | 2 | return fn(null, _this); |
113 | }); | |
114 | }; | |
115 | })(this)); | |
116 | }; | |
117 | ||
118 | 1 | return SocialModel; |
119 | ||
120 | })(); | |
121 | }; | |
122 | ||
123 | }).call(this); | |
124 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var qs, |
3 | __hasProp = {}.hasOwnProperty, | |
4 | 7 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
5 | ||
6 | 1 | qs = require('querystring'); |
7 | ||
8 | 1 | module.exports = function(app) { |
9 | 1 | var config; |
10 | 1 | config = app.get('facebook_config'); |
11 | 1 | return global.Facebook = (function(_super) { |
12 | 1 | __extends(Facebook, _super); |
13 | ||
14 | 1 | function Facebook() { |
15 | 4 | return Facebook.__super__.constructor.apply(this, arguments); |
16 | } | |
17 | ||
18 | 1 | Facebook.prototype.validate = function(fn) { |
19 | 4 | if (this.uid() == null) { |
20 | 1 | return fn(new BadRequest('Missing UID')); |
21 | } | |
22 | 3 | if (this.token() == null) { |
23 | 1 | return fn(new BadRequest('Missing Token')); |
24 | } | |
25 | 2 | return fn(null, this); |
26 | }; | |
27 | ||
28 | 1 | Facebook.prototype.access_token = function(fn) { |
29 | 0 | var opts; |
30 | 0 | opts = { |
31 | url: "" + config.url + "/oauth/access_token", | |
32 | qs: { | |
33 | client_id: config.app_id, | |
34 | client_secret: config.app_secret, | |
35 | grant_type: 'fb_exchange_token', | |
36 | fb_exchange_token: this.token() | |
37 | } | |
38 | }; | |
39 | 0 | return request.get(opts, function(err, r, body) { |
40 | 0 | var token; |
41 | 0 | if (err != null) { |
42 | 0 | return fn(err); |
43 | } | |
44 | 0 | token = qs.parse(body).access_token; |
45 | 0 | if (token == null) { |
46 | 0 | return fn(new BadRequest('Missing token')); |
47 | } | |
48 | 0 | return fn(null, token); |
49 | }); | |
50 | }; | |
51 | ||
52 | 1 | Facebook.prototype.fetch = function(fn) { |
53 | 3 | return request.get("" + config.url + "/me?access_token=" + (this.token()), (function(_this) { |
54 | 3 | return function(e, r, body) { |
55 | 3 | if ((r != null ? r.statusCode : void 0) !== 200) { |
56 | 0 | return fn(new BadRequest(body)); |
57 | } | |
58 | 3 | _this.model.uid = body.id.toString(); |
59 | 3 | _this.model.name = body.name; |
60 | 3 | _this.model.username = body.username; |
61 | 3 | _this.model.avatar = "" + config.url + "/" + (_this.uid()) + "/picture?type=large"; |
62 | 3 | _this.model.email = body.email; |
63 | 3 | _this.model.gender = body.gender; |
64 | 3 | return fn(null, _this); |
65 | }; | |
66 | })(this)); | |
67 | }; | |
68 | ||
69 | 1 | Facebook.prototype.create_user = function(fn) { |
70 | 1 | var data, username; |
71 | 1 | username = (function() { |
72 | 1 | switch (true) { |
73 | case this.username() != null: | |
74 | 0 | return this.username(); |
75 | default: | |
76 | 1 | return this.name().replace(/\s/g, '.').substr(0, 15); |
77 | } | |
78 | }).call(this); | |
79 | 1 | data = { |
80 | name: this.name(), | |
81 | username: username, | |
82 | email: this.email(), | |
83 | password: utils.randomString() | |
84 | }; | |
85 | 1 | return new User(data).save((function(_this) { |
86 | 1 | return function(err, user) { |
87 | 1 | if (err != null) { |
88 | 0 | return fn(err); |
89 | } | |
90 | 1 | _this.user = user; |
91 | 1 | return fn(null, _this); |
92 | }; | |
93 | })(this)); | |
94 | }; | |
95 | ||
96 | 1 | return Facebook; |
97 | ||
98 | })(SocialModel); | |
99 | }; | |
100 | ||
101 | }).call(this); | |
102 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var fs; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | module.exports = function(app) { |
7 | 1 | var file, _i, _len, _ref, _results; |
8 | 1 | _ref = fs.readdirSync(__dirname); |
9 | 1 | _results = []; |
10 | 1 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
11 | 6 | file = _ref[_i]; |
12 | 6 | if (/^((?!index).)*$/.test(file)) { |
13 | 5 | _results.push(require("/home/travis/build/Tivoli/curio/server/mongo/models/./" + file)(app)); |
14 | } | |
15 | } | |
16 | 1 | return _results; |
17 | }; | |
18 | ||
19 | }).call(this); | |
20 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var __hasProp = {}.hasOwnProperty, |
3 | 23 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
4 | ||
5 | 1 | module.exports = function(app) { |
6 | 1 | var mongo; |
7 | 1 | mongo = app.mongo; |
8 | 1 | return global.Page = (function(_super) { |
9 | 1 | __extends(Page, _super); |
10 | ||
11 | 1 | function Page() { |
12 | 145 | return Page.__super__.constructor.apply(this, arguments); |
13 | } | |
14 | ||
15 | 1 | Page.collection = mongo.pages; |
16 | ||
17 | 1 | Page.prototype.whitelist = ['path', 'title', 'context']; |
18 | ||
19 | 1 | Page.prototype.title = function() { |
20 | 147 | return this.model.title; |
21 | }; | |
22 | ||
23 | 1 | Page.prototype.path = function() { |
24 | 148 | return this.model.path_original || this.model.path; |
25 | }; | |
26 | ||
27 | 1 | Page.prototype.context = function() { |
28 | 146 | return this.model.context; |
29 | }; | |
30 | ||
31 | 1 | Page.prototype.validate = function(fn) { |
32 | 13 | var _ref, _ref1, _ref2; |
33 | 13 | if (!((_ref = this.path()) != null ? _ref.length : void 0)) { |
34 | 1 | return fn(new BadRequest('Missing Path')); |
35 | } | |
36 | 12 | if (!((_ref1 = this.title()) != null ? _ref1.length : void 0)) { |
37 | 1 | return fn(new BadRequest('Missing Title')); |
38 | } | |
39 | 11 | if (!((_ref2 = this.context()) != null ? _ref2.length : void 0)) { |
40 | 1 | return fn(new BadRequest('Missing Context')); |
41 | } | |
42 | 10 | return fn(null, this); |
43 | }; | |
44 | ||
45 | 1 | Page.prototype.amend = function(values) { |
46 | 13 | var _ref; |
47 | 13 | Page.__super__.amend.call(this, values); |
48 | 13 | return this.set({ |
49 | path: (_ref = values.path) != null ? _ref.toLowerCase() : void 0, | |
50 | path_original: values.path | |
51 | }); | |
52 | }; | |
53 | ||
54 | 1 | Page.prototype.toJSON = function() { |
55 | 135 | return { |
56 | id: this.id(), | |
57 | path: this.path(), | |
58 | title: this.title(), | |
59 | context: this.context() | |
60 | }; | |
61 | }; | |
62 | ||
63 | 1 | return Page; |
64 | ||
65 | })(Model); | |
66 | }; | |
67 | ||
68 | }).call(this); | |
69 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var __hasProp = {}.hasOwnProperty, |
3 | 23 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
4 | ||
5 | 1 | module.exports = function(app) { |
6 | 1 | var mongo; |
7 | 1 | mongo = app.mongo; |
8 | 1 | return global.Post = (function(_super) { |
9 | 1 | __extends(Post, _super); |
10 | ||
11 | 1 | function Post() { |
12 | 231 | return Post.__super__.constructor.apply(this, arguments); |
13 | } | |
14 | ||
15 | 1 | Post.collection = mongo.posts; |
16 | ||
17 | 1 | Post.prototype.whitelist = ['title', 'context']; |
18 | ||
19 | 1 | Post.prototype._user = function() { |
20 | 235 | return this.model._user; |
21 | }; | |
22 | ||
23 | 1 | Post.prototype.title = function() { |
24 | 232 | return this.model.title; |
25 | }; | |
26 | ||
27 | 1 | Post.prototype.context = function() { |
28 | 231 | return this.model.context; |
29 | }; | |
30 | ||
31 | 1 | Post.prototype.validate = function(fn) { |
32 | 9 | var _ref, _ref1; |
33 | 9 | if (!((_ref = this.title()) != null ? _ref.length : void 0)) { |
34 | 1 | return fn(new BadRequest('Missing Title')); |
35 | } | |
36 | 8 | if (!((_ref1 = this.context()) != null ? _ref1.length : void 0)) { |
37 | 1 | return fn(new BadRequest('Missing Context')); |
38 | } | |
39 | 7 | return User.collection.find({ |
40 | _id: this._user() | |
41 | }).count((function(_this) { | |
42 | 7 | return function(err, count) { |
43 | 7 | if (!count) { |
44 | 1 | return fn(err || new BadRequest('Invalid User')); |
45 | } | |
46 | 6 | return fn(null, _this); |
47 | }; | |
48 | })(this)); | |
49 | }; | |
50 | ||
51 | 1 | Post.prototype.amend = function(values) { |
52 | 8 | Post.__super__.amend.call(this, values); |
53 | 8 | return this.set({ |
54 | slug: _(values.title).toSlug() | |
55 | }); | |
56 | }; | |
57 | ||
58 | 1 | Post.prototype.toJSON = function() { |
59 | 223 | var _ref; |
60 | 223 | return { |
61 | id: this.id(), | |
62 | title: this.title(), | |
63 | slug: this.slug(), | |
64 | created_at: this.created_at(), | |
65 | context: this.context(), | |
66 | author: (_ref = this.user) != null ? _ref.toJSON() : void 0 | |
67 | }; | |
68 | }; | |
69 | ||
70 | 1 | return Post; |
71 | ||
72 | })(Model); | |
73 | }; | |
74 | ||
75 | }).call(this); | |
76 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var __hasProp = {}.hasOwnProperty, |
3 | 23 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
4 | ||
5 | 1 | module.exports = function(app) { |
6 | 1 | var mongo; |
7 | 1 | mongo = app.mongo; |
8 | 1 | return global.SiteConfig = (function(_super) { |
9 | 1 | __extends(SiteConfig, _super); |
10 | ||
11 | 1 | function SiteConfig() { |
12 | 9 | return SiteConfig.__super__.constructor.apply(this, arguments); |
13 | } | |
14 | ||
15 | 1 | SiteConfig.collection = mongo.configs; |
16 | ||
17 | 1 | SiteConfig.find = function(id, fn) { |
18 | 9 | id = id.toLowerCase(); |
19 | 9 | return this.collection.findOne({ |
20 | _id: id | |
21 | }, function(err, data) { | |
22 | 9 | if (err != null) { |
23 | 0 | return fn(err); |
24 | } | |
25 | 9 | if (data != null) { |
26 | 8 | return fn(null, new SiteConfig(data)); |
27 | } | |
28 | 1 | return new SiteConfig({ |
29 | _id: id | |
30 | }).save(fn); | |
31 | }); | |
32 | }; | |
33 | ||
34 | 1 | SiteConfig.prototype.blacklist = ['id', '_id']; |
35 | ||
36 | 1 | SiteConfig.prototype.toJSON = function() { |
37 | 9 | var json; |
38 | 9 | json = _(this.model).clone(); |
39 | 9 | json.id = this._id(); |
40 | 9 | json.images = this.images; |
41 | 9 | delete json._id; |
42 | 9 | return json; |
43 | }; | |
44 | ||
45 | 1 | return SiteConfig; |
46 | ||
47 | })(Model); | |
48 | }; | |
49 | ||
50 | }).call(this); | |
51 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var bcrypt, blocked, k, _i, _len, |
3 | __hasProp = {}.hasOwnProperty, | |
4 | 23 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, |
5 | 0 | __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
6 | ||
7 | 1 | bcrypt = require('bcrypt'); |
8 | ||
9 | 1 | blocked = require('../data/reserved'); |
10 | ||
11 | 1 | for (_i = 0, _len = blocked.length; _i < _len; _i++) { |
12 | 142 | k = blocked[_i]; |
13 | 142 | blocked.push(fleck.pluralize(k)); |
14 | } | |
15 | ||
16 | 1 | module.exports = function(app) { |
17 | 1 | var mongo; |
18 | 1 | mongo = app.mongo; |
19 | 1 | return global.User = (function(_super) { |
20 | 1 | __extends(User, _super); |
21 | ||
22 | 1 | function User() { |
23 | 429 | return User.__super__.constructor.apply(this, arguments); |
24 | } | |
25 | ||
26 | 1 | User.collection = mongo.users; |
27 | ||
28 | 1 | User.order_by = [['email', 'asc']]; |
29 | ||
30 | 1 | User.find_by_auth = function(source, uid, fn) { |
31 | 2 | var query; |
32 | 2 | query = { |
33 | 'authentications.source': source, | |
34 | 'authentications.uid': uid | |
35 | }; | |
36 | 2 | return this.collection.findOne(query, function(err, data) { |
37 | 2 | if (data == null) { |
38 | 1 | return fn(err || new NotFound('User Not Found')); |
39 | } | |
40 | 1 | return new User(data).populate(fn); |
41 | }); | |
42 | }; | |
43 | ||
44 | 1 | User.find_by_token = function(token, fn) { |
45 | 3 | if (!((token != null) && _(token).isString())) { |
46 | 1 | return fn(new Unauthorized); |
47 | } | |
48 | 2 | return mongo.tokens.findOne({ |
49 | _id: token | |
50 | }, function(err, token) { | |
51 | 2 | if (token == null) { |
52 | 1 | return fn(err || new Unauthorized); |
53 | } | |
54 | 1 | return User.find(token._user, fn); |
55 | }); | |
56 | }; | |
57 | ||
58 | 1 | User.authenticate = function(email, pass, fn) { |
59 | 13 | if (!_(email).isEmail()) { |
60 | 3 | return fn(new Unauthorized); |
61 | } | |
62 | 10 | if (!(_(pass).isString() && pass.length)) { |
63 | 1 | return fn(new Unauthorized); |
64 | } | |
65 | 9 | return this.find(email, function(err, user) { |
66 | 9 | if (err != null) { |
67 | 0 | return fn(err); |
68 | } | |
69 | 9 | return user.set_self().match_password(pass, fn); |
70 | }); | |
71 | }; | |
72 | ||
73 | 1 | User.prototype.whitelist = ['email', 'username', 'password', 'name']; |
74 | ||
75 | 1 | User.prototype.email = function() { |
76 | 207 | return this.model.email; |
77 | }; | |
78 | ||
79 | 1 | User.prototype.username = function() { |
80 | 434 | return this.model.username_original || this.model.username; |
81 | }; | |
82 | ||
83 | 1 | User.prototype.password = function() { |
84 | 37 | return this.model.password; |
85 | }; | |
86 | ||
87 | 1 | User.prototype.name = function() { |
88 | 435 | return this.model.name; |
89 | }; | |
90 | ||
91 | 1 | User.prototype.avatar = function() { |
92 | 404 | return this.model.avatar; |
93 | }; | |
94 | ||
95 | 1 | User.prototype.settings = function() { |
96 | 179 | return this.model.settings; |
97 | }; | |
98 | ||
99 | 1 | User.prototype.authentications = function() { |
100 | 177 | return this.model.authentications; |
101 | }; | |
102 | ||
103 | 1 | User.prototype.hashed_password = function() { |
104 | 9 | return this.model.hashed_password; |
105 | }; | |
106 | ||
107 | 1 | User.prototype.is_admin = function() { |
108 | 404 | var _ref; |
109 | 404 | return __indexOf.call(((_ref = this.model) != null ? _ref.roles : void 0) || [], 'admin') >= 0; |
110 | }; | |
111 | ||
112 | 1 | User.prototype.defaults = function() { |
113 | 13 | return _(this.model).defaults({ |
114 | settings: {}, | |
115 | authentications: [] | |
116 | }); | |
117 | }; | |
118 | ||
119 | 1 | User.prototype.set_self = function() { |
120 | 185 | this.is_self = true; |
121 | 185 | return this; |
122 | }; | |
123 | ||
124 | 1 | User.prototype.validate = function(fn) { |
125 | 23 | var _ref, _ref1; |
126 | 23 | if (this._id() == null) { |
127 | 12 | if (this.email() == null) { |
128 | 1 | return fn(new BadRequest('Missing Email')); |
129 | } | |
130 | 11 | if (this.name() == null) { |
131 | 1 | return fn(new BadRequest('Missing Name')); |
132 | } | |
133 | 10 | if (this.password() == null) { |
134 | 1 | return fn(new BadRequest('Missing Password')); |
135 | } | |
136 | } | |
137 | 20 | if (!_(this.email()).isEmail()) { |
138 | 2 | return fn(new BadRequest('Invalid Email')); |
139 | } | |
140 | 18 | if (!_(this.name()).isName()) { |
141 | 2 | return fn(new BadRequest('Invalid Name')); |
142 | } | |
143 | 16 | if (!_(this.username()).isUsername()) { |
144 | 2 | return fn(new BadRequest('Invalid Username')); |
145 | } | |
146 | 14 | if (_ref = this.username(), __indexOf.call(blocked, _ref) >= 0) { |
147 | 2 | return fn(new BadRequest('Invalid Username')); |
148 | } | |
149 | 12 | if (((_ref1 = this.password()) != null ? _ref1.length : void 0) < 6) { |
150 | 2 | return fn(new BadRequest('Password too short')); |
151 | } | |
152 | 10 | if (this.password() == null) { |
153 | 5 | return fn(null, this); |
154 | } | |
155 | 5 | return this.hash_password(fn); |
156 | }; | |
157 | ||
158 | 1 | User.prototype.amend = function(values) { |
159 | 23 | var _ref, _ref1; |
160 | 23 | User.__super__.amend.call(this, values); |
161 | 23 | return this.set({ |
162 | email: (_ref = values.email) != null ? _ref.toLowerCase() : void 0, | |
163 | username: (_ref1 = values.username) != null ? _ref1.toLowerCase() : void 0, | |
164 | username_original: values.username | |
165 | }); | |
166 | }; | |
167 | ||
168 | 1 | User.prototype.hash_password = function(fn) { |
169 | 5 | return bcrypt.hash(this.password(), 10, (function(_this) { |
170 | 5 | return function(err, hash) { |
171 | 5 | if (err != null) { |
172 | 0 | return fn(err); |
173 | } | |
174 | 5 | _this.set({ |
175 | hashed_password: hash | |
176 | }); | |
177 | 5 | return fn(null, _this); |
178 | }; | |
179 | })(this)); | |
180 | }; | |
181 | ||
182 | 1 | User.prototype.match_password = function(pass, fn) { |
183 | 9 | return bcrypt.compare(pass, this.hashed_password(), (function(_this) { |
184 | 9 | return function(err, result) { |
185 | 9 | if (!result) { |
186 | 2 | return fn(err || new Unauthorized('Invalid Password')); |
187 | } | |
188 | 7 | return fn(null, _this); |
189 | }; | |
190 | })(this)); | |
191 | }; | |
192 | ||
193 | 1 | User.prototype.update_role = function(method, role, fn) { |
194 | 7 | var query; |
195 | 7 | if (!_(role).isString()) { |
196 | 1 | return fn(new BadRequest('Missing Role')); |
197 | } | |
198 | 6 | query = (function() { |
199 | 6 | switch (method) { |
200 | case 'add': | |
201 | 3 | return { |
202 | $addToSet: { | |
203 | roles: role | |
204 | } | |
205 | }; | |
206 | default: | |
207 | 3 | return { |
208 | $pull: { | |
209 | roles: role | |
210 | } | |
211 | }; | |
212 | } | |
213 | })(); | |
214 | 6 | return this.update(query, fn); |
215 | }; | |
216 | ||
217 | 1 | User.prototype.update_token = function(fn) { |
218 | 1 | var doc; |
219 | 1 | doc = { |
220 | _id: "" + (utils.randomString(24)) + "." + (this.id()), | |
221 | _user: this._id(), | |
222 | expires: new Date() | |
223 | }; | |
224 | 1 | return mongo.tokens.insert(doc, function(err, doc) { |
225 | 1 | if (err != null) { |
226 | 0 | return fn(new MongoError(err.message)); |
227 | } | |
228 | 1 | return fn(null, doc); |
229 | }); | |
230 | }; | |
231 | ||
232 | 1 | User.prototype.save = function(fn) { |
233 | 13 | delete this.model.password; |
234 | 13 | return User.__super__.save.call(this, fn); |
235 | }; | |
236 | ||
237 | 1 | User.prototype.toJSON = function() { |
238 | 404 | var json; |
239 | 404 | json = { |
240 | id: this.id(), | |
241 | username: this.username(), | |
242 | name: this.name(), | |
243 | avatar: this.avatar(), | |
244 | is_admin: this.is_admin() | |
245 | }; | |
246 | 404 | if (this.is_self) { |
247 | 175 | _(json).extend({ |
248 | email: this.email(), | |
249 | settings: this.settings(), | |
250 | authentications: this.authentications() | |
251 | }); | |
252 | } | |
253 | 404 | return json; |
254 | }; | |
255 | ||
256 | 1 | return User; |
257 | ||
258 | })(Model); | |
259 | }; | |
260 | ||
261 | }).call(this); | |
262 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var fs, json2mongo, path; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | path = require('path'); |
7 | ||
8 | 1 | json2mongo = require('json2mongo'); |
9 | ||
10 | 1 | module.exports = function(app) { |
11 | 1 | var dir_seeds, module; |
12 | 1 | module = {}; |
13 | 1 | dir_seeds = module.dir = "" + __dirname + "/data/seeds"; |
14 | 1 | module.seed = function(done) { |
15 | 1 | var mongo; |
16 | 1 | mongo = app.mongo; |
17 | 1 | return fs.readdir(dir_seeds, function(err, files) { |
18 | 1 | if (err != null) { |
19 | 0 | return done(err); |
20 | } | |
21 | 1 | return async.each(files, function(file, fn) { |
22 | 3 | var col, docs; |
23 | 3 | col = /^(\w+)\./.exec(file)[1]; |
24 | 3 | docs = require(path.join(dir_seeds, file)); |
25 | 3 | docs = json2mongo(docs); |
26 | 3 | if (app.get('env') !== 'test') { |
27 | 0 | console.log(' Seeding %s with %d records', col, docs.length); |
28 | } | |
29 | 3 | return mongo[col].insert(docs, { |
30 | safe: true, | |
31 | keepGoing: true | |
32 | }, fn); | |
33 | }, done); | |
34 | }); | |
35 | }; | |
36 | 1 | return module; |
37 | }; | |
38 | ||
39 | }).call(this); | |
40 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var marked, qs; |
3 | ||
4 | 1 | marked = typeof exports !== "undefined" && exports !== null ? require('marked') : window.marked; |
5 | ||
6 | 1 | qs = typeof exports !== "undefined" && exports !== null ? require('querystring').stringify : $.param; |
7 | ||
8 | 1 | dust.helpers.markdown = function(chunk, context, bodies, params) { |
9 | 2 | if (bodies.block) { |
10 | 2 | return chunk.capture(bodies.block, context, function(string, chunk) { |
11 | 2 | return chunk.end(marked(string)); |
12 | }); | |
13 | } | |
14 | 0 | return chunk; |
15 | }; | |
16 | ||
17 | 1 | dust.helpers.moment = function(chunk, context, bodies, params) { |
18 | 60 | if (bodies.block) { |
19 | 60 | return chunk.capture(bodies.block, context, function(string, chunk) { |
20 | 60 | var format; |
21 | 60 | format = 'MMMM Do YYYY, h:mm a'; |
22 | 60 | if (params != null ? params.format : void 0) { |
23 | 0 | format = dust.helpers.tap(params.format, chunk, context); |
24 | } | |
25 | 60 | return chunk.end(moment(string).format(format)); |
26 | }); | |
27 | } | |
28 | 0 | return chunk; |
29 | }; | |
30 | ||
31 | }).call(this); | |
32 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | _.mixin({ |
3 | isEmail: function(string) { | |
4 | 355 | if (!_(string).isString()) { |
5 | 239 | return false; |
6 | } | |
7 | 116 | return /^[a-z0-9_.%+\-]+@[0-9a-z.\-]+\.[a-z]{2,6}$/i.test(string); |
8 | }, | |
9 | isUsername: function(string) { | |
10 | 333 | if (!_(string).isString()) { |
11 | 236 | return false; |
12 | } | |
13 | 97 | return /^[\w\d\.-]{2,15}$/i.test(string); |
14 | }, | |
15 | isName: function(string) { | |
16 | 29 | if (!_(string).isString()) { |
17 | 6 | return false; |
18 | } | |
19 | 23 | return /^[\u00c0-\u01ff'\w\d\s\.\-]{3,}$/i.test(string); |
20 | }, | |
21 | isObjectID: function(string) { | |
22 | 311 | return /[0-9a-f]{24}/.test(string); |
23 | }, | |
24 | isSlug: function(string) { | |
25 | 315 | if (!_(string).isString()) { |
26 | 236 | return false; |
27 | } | |
28 | 79 | return /^[a-z0-9-]+$/.test(string); |
29 | }, | |
30 | isISODate: function(string) { | |
31 | 13 | if (!_(string).isString()) { |
32 | 9 | return false; |
33 | } | |
34 | 4 | return /^(\d{4})(?:-?W(\d+)(?:-?(\d+)D?)?|(?:-(\d+))?-(\d+))(?:[T ](\d+):(\d+)(?::(\d+)(?:\.(\d+))?)?)?(?:Z(-?\d*))?$/.test(string); |
35 | }, | |
36 | toSlug: function(string) { | |
37 | 16 | if (!_(string).isString()) { |
38 | 1 | return; |
39 | } | |
40 | 15 | return string.trim().toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '').replace(/-+/g, '-'); |
41 | }, | |
42 | formatCurrency: function(num) { | |
43 | 3 | var cents, dollars; |
44 | 3 | num = num.toString(); |
45 | 3 | dollars = num.slice(0, -2); |
46 | 3 | cents = num.slice(-2); |
47 | 3 | dollars = dollars.replace(/\B(?=(\d{3})+(?!\d))/g, ','); |
48 | 3 | return "$" + dollars + "." + cents; |
49 | } | |
50 | }); | |
51 | ||
52 | }).call(this); | |
53 |
Line | Hits | Source |
---|---|---|
1 | 1 | (function() { |
2 | 1 | var fs; |
3 | ||
4 | 1 | fs = require('fs'); |
5 | ||
6 | 1 | module.exports = function(app) { |
7 | 1 | var module; |
8 | 1 | module = {}; |
9 | 1 | module.randomString = function(length) { |
10 | 2 | var str; |
11 | 2 | if (length == null) { |
12 | 1 | length = 32; |
13 | } | |
14 | 2 | str = ''; |
15 | 2 | while (str.length < length) { |
16 | 5 | str += Math.random().toString(36).substr(2); |
17 | } | |
18 | 2 | return str.substr(0, length); |
19 | }; | |
20 | 1 | module.shortId = function() { |
21 | 1 | var id; |
22 | 1 | id = new app.mongo.ObjectID().toHexString(); |
23 | 1 | return id.substr(0, 10); |
24 | }; | |
25 | 1 | module.walk_dir = function(dir) { |
26 | 14 | var file, results, stat, _i, _len, _ref; |
27 | 14 | results = []; |
28 | 14 | _ref = fs.readdirSync(dir); |
29 | 14 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
30 | 32 | file = _ref[_i]; |
31 | 32 | file = "" + dir + "/" + file; |
32 | 32 | stat = fs.statSync(file); |
33 | 32 | switch (true) { |
34 | case stat != null ? stat.isDirectory() : void 0: | |
35 | 11 | results = results.concat(utils.walk_dir(file)); |
36 | 11 | break; |
37 | default: | |
38 | 21 | results.push(file); |
39 | } | |
40 | } | |
41 | 14 | return results; |
42 | }; | |
43 | 1 | module.is_json_request = function(req) { |
44 | 3 | return req.is('json') || _(req.accepted).any(function(a) { |
45 | 3 | return a.subtype === 'json'; |
46 | }); | |
47 | }; | |
48 | 1 | module.save_and_send = function(req, res, next) { |
49 | 46 | var model; |
50 | 46 | model = req.resource; |
51 | 46 | return async.waterfall([ |
52 | function(done) { | |
53 | 46 | return done(null, model.amend(req.body)); |
54 | }, function(model, done) { | |
55 | 46 | return model.validate(done); |
56 | }, function(model, done) { | |
57 | 28 | return model.save(done); |
58 | }, function(model, done) { | |
59 | 24 | return model.populate(done); |
60 | } | |
61 | ], function(err, model) { | |
62 | 46 | if (err != null) { |
63 | 22 | return next(err); |
64 | } | |
65 | 24 | return res.json(model.toJSON()); |
66 | }); | |
67 | }; | |
68 | 1 | module.cursorJSON = function(cursor, fn) { |
69 | 29 | var data, model, stream; |
70 | 29 | stream = cursor.stream(); |
71 | 29 | model = this.to_model(stream); |
72 | 29 | data = []; |
73 | 29 | stream.on('data', function(item) { |
74 | 480 | stream.pause(); |
75 | 480 | return new model(item).populate(function(err, item) { |
76 | 480 | if (item == null) { |
77 | 0 | return stream.resume(); |
78 | } | |
79 | 480 | if (typeof item.set_self === "function") { |
80 | 150 | item.set_self(); |
81 | } | |
82 | 480 | data.push(item.toJSON()); |
83 | 480 | return stream.resume(); |
84 | }); | |
85 | }); | |
86 | 29 | return stream.on('close', function() { |
87 | 29 | return fn(null, data); |
88 | }); | |
89 | }; | |
90 | 1 | module.streamJSON = function(req, res, next, cursor) { |
91 | 21 | return utils.cursorJSON(cursor, function(err, data) { |
92 | 21 | if (err != null) { |
93 | 0 | return next(err); |
94 | } | |
95 | 21 | return res.json(data); |
96 | }); | |
97 | }; | |
98 | 1 | module.load_shared = function(dir) { |
99 | 1 | var file, _i, _len, _ref, _results; |
100 | 1 | _ref = this.walk_dir(dir); |
101 | 1 | _results = []; |
102 | 1 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
103 | 2 | file = _ref[_i]; |
104 | 2 | _results.push(require(file)); |
105 | } | |
106 | 1 | return _results; |
107 | }; | |
108 | 1 | module.to_model = function(source) { |
109 | 40 | source = (function() { |
110 | 40 | switch (source.constructor.name) { |
111 | case 'CursorStream': | |
112 | 29 | return source._cursor.collection.collectionName; |
113 | case 'String': | |
114 | 11 | return source; |
115 | } | |
116 | })(); | |
117 | 40 | return global[fleck.inflect(source, 'singularize', 'upperCamelize')]; |
118 | }; | |
119 | 1 | return module; |
120 | }; | |
121 | ||
122 | }).call(this); | |
123 |