Skip to content

Commit bcc50ec

Browse files
committed
first commit
1 parent 8ea77c5 commit bcc50ec

File tree

114 files changed

+8603
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+8603
-3
lines changed

.DS_Store

6 KB
Binary file not shown.

Gruntfile.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Gruntfile
3+
*
4+
* This Node script is executed when you run `grunt` or `sails lift`.
5+
* It's purpose is to load the Grunt tasks in your project's `tasks`
6+
* folder, and allow you to add and remove tasks as you see fit.
7+
* For more information on how this works, check out the `README.md`
8+
* file that was generated in your `tasks` folder.
9+
*
10+
* WARNING:
11+
* Unless you know what you're doing, you shouldn't change this file.
12+
* Check out the `tasks` directory instead.
13+
*/
14+
15+
module.exports = function(grunt) {
16+
17+
18+
// Load the include-all library in order to require all of our grunt
19+
// configurations and task registrations dynamically.
20+
var includeAll;
21+
try {
22+
includeAll = require('include-all');
23+
} catch (e0) {
24+
try {
25+
includeAll = require('sails/node_modules/include-all');
26+
}
27+
catch(e1) {
28+
console.error('Could not find `include-all` module.');
29+
console.error('Skipping grunt tasks...');
30+
console.error('To fix this, please run:');
31+
console.error('npm install include-all --save`');
32+
console.error();
33+
34+
grunt.registerTask('default', []);
35+
return;
36+
}
37+
}
38+
39+
40+
/**
41+
* Loads Grunt configuration modules from the specified
42+
* relative path. These modules should export a function
43+
* that, when run, should either load/configure or register
44+
* a Grunt task.
45+
*/
46+
function loadTasks(relPath) {
47+
return includeAll({
48+
dirname: require('path').resolve(__dirname, relPath),
49+
filter: /(.+)\.js$/
50+
}) || {};
51+
}
52+
53+
/**
54+
* Invokes the function from a Grunt configuration module with
55+
* a single argument - the `grunt` object.
56+
*/
57+
function invokeConfigFn(tasks) {
58+
for (var taskName in tasks) {
59+
if (tasks.hasOwnProperty(taskName)) {
60+
tasks[taskName](grunt);
61+
}
62+
}
63+
}
64+
65+
66+
67+
68+
// Load task functions
69+
var taskConfigurations = loadTasks('./tasks/config'),
70+
registerDefinitions = loadTasks('./tasks/register');
71+
72+
// (ensure that a default task exists)
73+
if (!registerDefinitions.default) {
74+
registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); };
75+
}
76+
77+
// Run task functions to configure Grunt.
78+
invokeConfigFn(taskConfigurations);
79+
invokeConfigFn(registerDefinitions);
80+
81+
};

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
sails-designer
2-
==============
1+
# sails-designer
32

4-
A simple sails app starter for designers
3+
a [Sails](http://sailsjs.org) application

api/controllers/.gitkeep

Whitespace-only changes.

api/models/.gitkeep

Whitespace-only changes.

api/policies/sessionAuth.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* sessionAuth
3+
*
4+
* @module :: Policy
5+
* @description :: Simple policy to allow any authenticated user
6+
* Assumes that your login action in one of your controllers sets `req.session.authenticated = true;`
7+
* @docs :: http://sailsjs.org/#!documentation/policies
8+
*
9+
*/
10+
module.exports = function(req, res, next) {
11+
12+
// User is allowed, proceed to the next policy,
13+
// or if this is the last policy, the controller
14+
if (req.session.authenticated) {
15+
return next();
16+
}
17+
18+
// User is not allowed
19+
// (default res.forbidden() behavior can be overridden in `config/403.js`)
20+
return res.forbidden('You are not permitted to perform this action.');
21+
};

api/responses/badRequest.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* 400 (Bad Request) Handler
3+
*
4+
* Usage:
5+
* return res.badRequest();
6+
* return res.badRequest(data);
7+
* return res.badRequest(data, 'some/specific/badRequest/view');
8+
*
9+
* e.g.:
10+
* ```
11+
* return res.badRequest(
12+
* 'Please choose a valid `password` (6-12 characters)',
13+
* 'trial/signup'
14+
* );
15+
* ```
16+
*/
17+
18+
module.exports = function badRequest(data, options) {
19+
20+
// Get access to `req`, `res`, & `sails`
21+
var req = this.req;
22+
var res = this.res;
23+
var sails = req._sails;
24+
25+
// Set status code
26+
res.status(400);
27+
28+
// Log error to console
29+
if (data !== undefined) {
30+
sails.log.verbose('Sending 400 ("Bad Request") response: \n',data);
31+
}
32+
else sails.log.verbose('Sending 400 ("Bad Request") response');
33+
34+
// Only include errors in response if application environment
35+
// is not set to 'production'. In production, we shouldn't
36+
// send back any identifying information about errors.
37+
if (sails.config.environment === 'production') {
38+
data = undefined;
39+
}
40+
41+
// If the user-agent wants JSON, always respond with JSON
42+
if (req.wantsJSON) {
43+
return res.jsonx(data);
44+
}
45+
46+
// If second argument is a string, we take that to mean it refers to a view.
47+
// If it was omitted, use an empty object (`{}`)
48+
options = (typeof options === 'string') ? { view: options } : options || {};
49+
50+
// If a view was provided in options, serve it.
51+
// Otherwise try to guess an appropriate view, or if that doesn't
52+
// work, just send JSON.
53+
if (options.view) {
54+
return res.view(options.view, { data: data });
55+
}
56+
57+
// If no second argument provided, try to serve the implied view,
58+
// but fall back to sending JSON(P) if no view can be inferred.
59+
else return res.guessView({ data: data }, function couldNotGuessView () {
60+
return res.jsonx(data);
61+
});
62+
63+
};
64+

api/responses/forbidden.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* 403 (Forbidden) Handler
3+
*
4+
* Usage:
5+
* return res.forbidden();
6+
* return res.forbidden(err);
7+
* return res.forbidden(err, 'some/specific/forbidden/view');
8+
*
9+
* e.g.:
10+
* ```
11+
* return res.forbidden('Access denied.');
12+
* ```
13+
*/
14+
15+
module.exports = function forbidden (data, options) {
16+
17+
// Get access to `req`, `res`, & `sails`
18+
var req = this.req;
19+
var res = this.res;
20+
var sails = req._sails;
21+
22+
// Set status code
23+
res.status(403);
24+
25+
// Log error to console
26+
if (data !== undefined) {
27+
sails.log.verbose('Sending 403 ("Forbidden") response: \n',data);
28+
}
29+
else sails.log.verbose('Sending 403 ("Forbidden") response');
30+
31+
// Only include errors in response if application environment
32+
// is not set to 'production'. In production, we shouldn't
33+
// send back any identifying information about errors.
34+
if (sails.config.environment === 'production') {
35+
data = undefined;
36+
}
37+
38+
// If the user-agent wants JSON, always respond with JSON
39+
if (req.wantsJSON) {
40+
return res.jsonx(data);
41+
}
42+
43+
// If second argument is a string, we take that to mean it refers to a view.
44+
// If it was omitted, use an empty object (`{}`)
45+
options = (typeof options === 'string') ? { view: options } : options || {};
46+
47+
// If a view was provided in options, serve it.
48+
// Otherwise try to guess an appropriate view, or if that doesn't
49+
// work, just send JSON.
50+
if (options.view) {
51+
return res.view(options.view, { data: data });
52+
}
53+
54+
// If no second argument provided, try to serve the default view,
55+
// but fall back to sending JSON(P) if any errors occur.
56+
else return res.view('403', { data: data }, function (err, html) {
57+
58+
// If a view error occured, fall back to JSON(P).
59+
if (err) {
60+
//
61+
// Additionally:
62+
// • If the view was missing, ignore the error but provide a verbose log.
63+
if (err.code === 'E_VIEW_FAILED') {
64+
sails.log.verbose('res.forbidden() :: Could not locate view for error page (sending JSON instead). Details: ',err);
65+
}
66+
// Otherwise, if this was a more serious error, log to the console with the details.
67+
else {
68+
sails.log.warn('res.forbidden() :: When attempting to render error page view, an error occured (sending JSON instead). Details: ', err);
69+
}
70+
return res.jsonx(data);
71+
}
72+
73+
return res.send(html);
74+
});
75+
76+
};
77+

api/responses/notFound.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* 404 (Not Found) Handler
3+
*
4+
* Usage:
5+
* return res.notFound();
6+
* return res.notFound(err);
7+
* return res.notFound(err, 'some/specific/notfound/view');
8+
*
9+
* e.g.:
10+
* ```
11+
* return res.notFound();
12+
* ```
13+
*
14+
* NOTE:
15+
* If a request doesn't match any explicit routes (i.e. `config/routes.js`)
16+
* or route blueprints (i.e. "shadow routes", Sails will call `res.notFound()`
17+
* automatically.
18+
*/
19+
20+
module.exports = function notFound (data, options) {
21+
22+
// Get access to `req`, `res`, & `sails`
23+
var req = this.req;
24+
var res = this.res;
25+
var sails = req._sails;
26+
27+
// Set status code
28+
res.status(404);
29+
30+
// Log error to console
31+
if (data !== undefined) {
32+
sails.log.verbose('Sending 404 ("Not Found") response: \n',data);
33+
}
34+
else sails.log.verbose('Sending 404 ("Not Found") response');
35+
36+
// Only include errors in response if application environment
37+
// is not set to 'production'. In production, we shouldn't
38+
// send back any identifying information about errors.
39+
if (sails.config.environment === 'production') {
40+
data = undefined;
41+
}
42+
43+
// If the user-agent wants JSON, always respond with JSON
44+
if (req.wantsJSON) {
45+
return res.jsonx(data);
46+
}
47+
48+
// If second argument is a string, we take that to mean it refers to a view.
49+
// If it was omitted, use an empty object (`{}`)
50+
options = (typeof options === 'string') ? { view: options } : options || {};
51+
52+
// If a view was provided in options, serve it.
53+
// Otherwise try to guess an appropriate view, or if that doesn't
54+
// work, just send JSON.
55+
if (options.view) {
56+
return res.view(options.view, { data: data });
57+
}
58+
59+
// If no second argument provided, try to serve the default view,
60+
// but fall back to sending JSON(P) if any errors occur.
61+
else return res.view('404', { data: data }, function (err, html) {
62+
63+
// If a view error occured, fall back to JSON(P).
64+
if (err) {
65+
//
66+
// Additionally:
67+
// • If the view was missing, ignore the error but provide a verbose log.
68+
if (err.code === 'E_VIEW_FAILED') {
69+
sails.log.verbose('res.notFound() :: Could not locate view for error page (sending JSON instead). Details: ',err);
70+
}
71+
// Otherwise, if this was a more serious error, log to the console with the details.
72+
else {
73+
sails.log.warn('res.notFound() :: When attempting to render error page view, an error occured (sending JSON instead). Details: ', err);
74+
}
75+
return res.jsonx(data);
76+
}
77+
78+
return res.send(html);
79+
});
80+
81+
};
82+

api/responses/ok.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* 200 (OK) Response
3+
*
4+
* Usage:
5+
* return res.ok();
6+
* return res.ok(data);
7+
* return res.ok(data, 'auth/login');
8+
*
9+
* @param {Object} data
10+
* @param {String|Object} options
11+
* - pass string to render specified view
12+
*/
13+
14+
module.exports = function sendOK (data, options) {
15+
16+
// Get access to `req`, `res`, & `sails`
17+
var req = this.req;
18+
var res = this.res;
19+
var sails = req._sails;
20+
21+
sails.log.silly('res.ok() :: Sending 200 ("OK") response');
22+
23+
// Set status code
24+
res.status(200);
25+
26+
// If appropriate, serve data as JSON(P)
27+
if (req.wantsJSON) {
28+
return res.jsonx(data);
29+
}
30+
31+
// If second argument is a string, we take that to mean it refers to a view.
32+
// If it was omitted, use an empty object (`{}`)
33+
options = (typeof options === 'string') ? { view: options } : options || {};
34+
35+
// If a view was provided in options, serve it.
36+
// Otherwise try to guess an appropriate view, or if that doesn't
37+
// work, just send JSON.
38+
if (options.view) {
39+
return res.view(options.view, { data: data });
40+
}
41+
42+
// If no second argument provided, try to serve the implied view,
43+
// but fall back to sending JSON(P) if no view can be inferred.
44+
else return res.guessView({ data: data }, function couldNotGuessView () {
45+
return res.jsonx(data);
46+
});
47+
48+
};

0 commit comments

Comments
 (0)