Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Commit

Permalink
making jshint fixes as well as fixes for running in production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
grawk committed Mar 28, 2014
1 parent 42d42d5 commit 21418b1
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 17 deletions.
155 changes: 155 additions & 0 deletions .jshintrc
@@ -0,0 +1,155 @@
{
// Whether the scan should stop on first error.
"passfail": false,
// Maximum errors before stopping.
"maxerr": 100,


// Predefined globals

// Whether the standard browser globals should be predefined.
"browser": false,
// Whether the Node.js environment globals should be predefined.
"node": true,
// Whether the Rhino environment globals should be predefined.
"rhino": false,
// Whether CouchDB globals should be predefined.
"couch": false,
// Whether the Windows Scripting Host environment globals should be predefined.
"wsh": false,

// Whether jQuery globals should be predefined.
"jquery": false,
// Whether Prototype and Scriptaculous globals should be predefined.
"prototypejs": false,
// Whether MooTools globals should be predefined.
"mootools": false,
// Whether Dojo Toolkit globals should be predefined.
"dojo": false,

// Custom predefined globals.
"predef": [],

// Development

// Whether debugger statements should be allowed.
"debug": false,
// Whether logging globals should be predefined (console, alert, etc.).
"devel": false,


// ECMAScript 5

// Whether the "use strict"; pragma should be required.
"strict": true,
// Whether global "use strict"; should be allowed (also enables strict).
"globalstrict": true,


// The Good Parts

// Whether automatic semicolon insertion should be allowed.
"asi": false,
// Whether line breaks should not be checked, e.g. `return [\n] x`.
"laxbreak": false,
// Whether bitwise operators (&, |, ^, etc.) should be forbidden.
"bitwise": false,
// Whether assignments inside `if`, `for` and `while` should be allowed. Usually
// conditions and loops are for comparison, not assignments.
"boss": true,
// Whether curly braces around all blocks should be required.
"curly": true,
// Whether `===` and `!==` should be required (instead of `==` and `!=`).
"eqeqeq": true,
// Whether `== null` comparisons should be allowed, even if `eqeqeq` is `true`.
"eqnull": false,
// Whether `eval` should be allowed.
"evil": false,
// Whether ExpressionStatement should be allowed as Programs.
"expr": true,
// Whether `for in` loops must filter with `hasOwnPrototype`.
"forin": false,
// Whether immediate invocations must be wrapped in parens, e.g.
// `( function(){}() );`.
"immed": true,
// Whether use before define should be forbidden.
"latedef": false,
// Whether functions should be allowed to be defined within loops.
"loopfunc": false,
// Whether arguments.caller and arguments.callee should be forbidden.
"noarg": false,
// Whether `.` should be forbidden in regexp literals.
"regexp": false,
// Whether unescaped first/last dash (-) inside brackets in regexps should be allowed.
"regexdash": false,
// Whether script-targeted URLs should be allowed.
"scripturl": false,
// Whether variable shadowing should be allowed.
"shadow": false,
// Whether `new function () { ... };` and `new Object;` should be allowed.
"supernew": false,
// Whether variables must be declared before used.
"undef": true,
// Whether `this` inside a non-constructor function should be allowed.
"validthis": false,
// Whether smarttabs should be allowed
// (http://www.emacswiki.org/emacs/SmartTabs).
"smarttabs": true,
// Whether the `__proto__` property should be allowed.
"proto": false,
// Whether one-case switch statements should be allowed.
"onecase": false,
// Whether non-standard (but widely adopted) globals should be predefined.
"nonstandard": false,
// Allow multiline strings.
"multistr": false,
// Whether line breaks should not be checked around commas.
"laxcomma": false,
// Whether semicolons may be ommitted for the trailing statements inside of a
// one-line blocks.
"lastsemic": false,
// Whether the `__iterator__` property should be allowed.
"iterator": false,
// Whether only function scope should be used for scope tests.
"funcscope": false,
// Whether es.next specific syntax should be allowed.
"esnext": false,


// Style preferences

// Whether constructor names must be capitalized.
"newcap": false,
// Whether empty blocks should be forbidden.
"noempty": false,
// Whether using `new` for side-effects should be forbidden.
"nonew": false,
// Whether names should be checked for leading or trailing underscores
// (object._attribute would be forbidden).
"nomen": false,
// Whether only one var statement per function should be allowed.
"onevar": false,
// Whether increment and decrement (`++` and `--`) should be forbidden.
"plusplus": false,
// Whether all forms of subscript notation are allowed.
"sub": false,
// Whether trailing whitespace rules apply.
"trailing": false,
// Specify indentation.
"indent": 4,
// Whether strict whitespace rules apply.
"white": false,
// Quote formatting
"quotmark": true,

// Complexity

// Maximum number of function parameters.
"maxparams": 5,
// Maximum block nesting depth.
"maxdepth": 3,
// Maximum number of statements per function.
"maxstatements": 25,
// Maximum cyclomatic complexity.
"maxcomplexity": 6
}
5 changes: 5 additions & 0 deletions config/middleware.json
Expand Up @@ -11,6 +11,11 @@
"factoryMethod": "flash",
"enabled": true
},
"locale": {
"module": "path:./lib/locale",
"priority": 95,
"enabled": true
},
//test if user session required to view page and if user has permission for given page
"isAuthenticated": {
"enabled": true,
Expand Down
2 changes: 1 addition & 1 deletion controllers/login.js
Expand Up @@ -31,7 +31,7 @@ module.exports = function (app) {

passport.authenticate('local', {
successRedirect: req.session.goingTo || '/profile',
failureRedirect: "/login",
failureRedirect: '/login',
failureFlash: true
})(req, res);

Expand Down
12 changes: 6 additions & 6 deletions lib/auth.js
Expand Up @@ -60,24 +60,24 @@ exports.isAuthenticated = function() {
return function(req, res, next) {
//access map
var auth = {
"/admin": true,
"/profile": true
'/admin': true,
'/profile': true
},
blacklist = {
"user": {
"/admin": true
'user': {
'/admin': true
}
},
route = req.url,
role = (req.user && req.user.role) ? req.user.role : "";
role = (req.user && req.user.role) ? req.user.role : '';
if (!auth[route]) {
next();
return;
}
else if (!req.isAuthenticated()) {
//If the user is not authorized, save the location that was being accessed so we can redirect afterwards.
req.session.goingTo = req.url;
req.flash("error", "Please log in to view this page");
req.flash('error', 'Please log in to view this page');
res.redirect('/login');
}
//Check blacklist for this user's role
Expand Down
2 changes: 1 addition & 1 deletion lib/crypto.js
Expand Up @@ -12,7 +12,7 @@ var crypto = function() {
if (cryptLevel === -1) {
cryptLevel = level;
}
}
};
};

module.exports = new crypto();
15 changes: 15 additions & 0 deletions lib/locale.js
@@ -0,0 +1,15 @@
'use strict';
module.exports = function () {
return function (req, res, next) {
var locale = req.cookies && req.cookies.locale;
//Set the locality for this response. The template will pick the appropriate bundle
if (locale) {
res.locals({
context: {
locality: locale
}
});
}
next();
};
};
13 changes: 6 additions & 7 deletions lib/spec.js
@@ -1,20 +1,19 @@
'use strict';

var userLib = require("./user")(),
var express = require('express'),
userLib = require('./user')(),
db = require('../lib/database'),
crypto = require('../lib/crypto');

var express = require('express');


module.exports = function spec(app) {

return {
onconfig: function(config, next) {
//var i18n = config.get('i18n');
var i18n = config.get('i18n'),
dbConfig = config.get("databaseConfig"),
cryptConfig = config.get("bcrypt");
dbConfig = config.get('databaseConfig'),
specialization = config.get('specialization'),
cryptConfig = config.get('bcrypt');
// Setup dev-tools for i18n compiling
if (i18n && config.get('middleware:devtools')) {
config.set('middleware:devtools:i18n', i18n);
Expand All @@ -24,7 +23,7 @@ module.exports = function spec(app) {
var engine = {
'views': config.get('express:views'),
'view engine': config.get('express:view engine'),
'specialization': config.get('specialization'),
'specialization': specialization,
'i18n': i18n
};

Expand Down
2 changes: 1 addition & 1 deletion lib/user.js
Expand Up @@ -33,7 +33,7 @@ var UserLibrary = function() {
done(null, user);
});
}
}
};
};

module.exports = UserLibrary;
2 changes: 1 addition & 1 deletion models/user.js
Expand Up @@ -44,7 +44,7 @@ var userModel = function () {
userSchema.methods.passwordMatches = function (plainText) {
var user = this;
return bcrypt.compareSync(plainText, user.password);
}
};


return mongoose.model('User', userSchema);
Expand Down

0 comments on commit 21418b1

Please sign in to comment.