chore(Merge): branch 'develop' into bs3
Conflicts: views/options/inventory/inventory.jade
This commit is contained in:
@@ -39,7 +39,7 @@ api.authWithSession = function(req, res, next) { //[todo] there is probably a mo
|
||||
if (!(req.session && req.session.userId))
|
||||
return res.json(401, NO_SESSION_FOUND);
|
||||
User.findOne({_id: uid}, function(err, user) {
|
||||
if (err) return res.json(500, {err: err});
|
||||
if (err) return next(err);
|
||||
if (_.isEmpty(user)) return res.json(401, NO_USER_FOUND);
|
||||
res.locals.user = user;
|
||||
next();
|
||||
@@ -107,14 +107,14 @@ api.loginLocal = function(req, res, next) {
|
||||
var password = req.body.password;
|
||||
if (!(username && password)) return res.json(401, {err:'Missing :username or :password in request body, please provide both'});
|
||||
User.findOne({'auth.local.username': username}, function(err, user){
|
||||
if (err) return res.json(500,{err:err});
|
||||
if (err) return next(err);
|
||||
if (!user) return res.json(401, {err:"Username '" + username + "' not found. Usernames are case-sensitive, click 'Forgot Password' if you can't remember the capitalization."});
|
||||
// We needed the whole user object first so we can get his salt to encrypt password comparison
|
||||
User.findOne({
|
||||
'auth.local.username': username,
|
||||
'auth.local.hashed_password': utils.encryptPassword(password, user.auth.local.salt)
|
||||
}, function(err, user){
|
||||
if (err) return res.json(500,{err:err});
|
||||
if (err) return next(err);
|
||||
if (!user) return res.json(401,{err:'Incorrect password'});
|
||||
res.json({id: user._id,token: user.apiToken});
|
||||
});
|
||||
@@ -164,7 +164,7 @@ api.resetPassword = function(req, res, next){
|
||||
hashed_password = utils.encryptPassword(newPassword, salt);
|
||||
|
||||
User.findOne({'auth.local.email':email}, function(err, user){
|
||||
if (err) return res.json(500,{err:err});
|
||||
if (err) return next(err);
|
||||
if (!user) return res.send(500, {err:"Couldn't find a user registered for email " + email});
|
||||
user.auth.local.salt = salt;
|
||||
user.auth.local.hashed_password = hashed_password;
|
||||
@@ -187,18 +187,18 @@ api.changePassword = function(req, res, next) {
|
||||
confirmNewPassword = req.body.confirmNewPassword;
|
||||
|
||||
if (newPassword != confirmNewPassword)
|
||||
return res.json(500, {err: "Password & Confirm don't match"});
|
||||
return res.json(401, {err: "Password & Confirm don't match"});
|
||||
|
||||
var salt = user.auth.local.salt,
|
||||
hashed_old_password = utils.encryptPassword(oldPassword, salt),
|
||||
hashed_new_password = utils.encryptPassword(newPassword, salt);
|
||||
|
||||
if (hashed_old_password !== user.auth.local.hashed_password)
|
||||
return res.json(500, {err:"Old password doesn't match"});
|
||||
return res.json(401, {err:"Old password doesn't match"});
|
||||
|
||||
user.auth.local.hashed_password = hashed_new_password;
|
||||
user.save(function(err, saved){
|
||||
if (err) res.json(500,{err:err});
|
||||
if (err) next(err);
|
||||
res.send(200);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ var path = require('path');
|
||||
var User = require('./models/user').model
|
||||
var limiter = require('connect-ratelimit');
|
||||
var logging = require('./logging');
|
||||
var domainMiddleware = require('domain-middleware');
|
||||
var cluster = require('cluster');
|
||||
|
||||
module.exports.apiThrottle = function(app) {
|
||||
if (nconf.get('NODE_ENV') !== 'production') return;
|
||||
@@ -24,6 +26,18 @@ module.exports.apiThrottle = function(app) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.domainMiddleware = function(server,mongoose) {
|
||||
return domainMiddleware({
|
||||
server: {
|
||||
close:function(){
|
||||
server.close();
|
||||
mongoose.connection.close();
|
||||
}
|
||||
},
|
||||
killTimeout: 10000
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.errorHandler = function(err, req, res, next) {
|
||||
//res.locals.domain.emit('error', err);
|
||||
// when we hit an error, send it to admin as an email. If no ADMIN_EMAIL is present, just send it to yourself (SMTP_USER)
|
||||
|
||||
+2
-1
@@ -68,7 +68,8 @@ var UserSchema = new Schema({
|
||||
level: Number, // 1-7, see https://trello.com/c/wkFzONhE/277-contributor-gear
|
||||
admin: Boolean,
|
||||
text: String, // Artisan, Friend, Blacksmith, etc
|
||||
contributions: String // a markdown textarea to list their contributions + links
|
||||
contributions: String, // a markdown textarea to list their contributions + links
|
||||
critical: String
|
||||
},
|
||||
|
||||
balance: {type: Number, 'default':0},
|
||||
|
||||
+16
-1
@@ -1,4 +1,5 @@
|
||||
// Only do the minimal amount of work before forking just in case of a dyno restart
|
||||
var cluster = require("cluster");
|
||||
var _ = require('lodash');
|
||||
var nconf = require('nconf');
|
||||
var utils = require('./utils');
|
||||
@@ -7,6 +8,18 @@ var logging = require('./logging');
|
||||
var isProd = nconf.get('NODE_ENV') === 'production';
|
||||
var isDev = nconf.get('NODE_ENV') === 'development';
|
||||
|
||||
if (cluster.isMaster && (isDev || isProd)) {
|
||||
// Fork workers.
|
||||
_.times(_.min([require('os').cpus().length,2]), function(){
|
||||
cluster.fork();
|
||||
});
|
||||
|
||||
cluster.on('disconnect', function(worker, code, signal) {
|
||||
var w = cluster.fork(); // replace the dead worker
|
||||
logging.info('[%s] [master:%s] worker:%s disconnect! new worker:%s fork', new Date(), process.pid, worker.process.pid, w.process.pid);
|
||||
});
|
||||
|
||||
} else {
|
||||
require('coffee-script'); // remove this once we've fully converted over
|
||||
var express = require("express");
|
||||
var http = require("http");
|
||||
@@ -79,6 +92,7 @@ var isDev = nconf.get('NODE_ENV') === 'development';
|
||||
|
||||
app.set("port", nconf.get('PORT'));
|
||||
middleware.apiThrottle(app);
|
||||
app.use(middleware.domainMiddleware(server,mongoose));
|
||||
if (!isProd) app.use(express.logger("dev"));
|
||||
app.use(express.compress());
|
||||
app.set("views", __dirname + "/../views");
|
||||
@@ -120,4 +134,5 @@ var isDev = nconf.get('NODE_ENV') === 'development';
|
||||
return logging.info("Express server listening on port " + app.get("port"));
|
||||
});
|
||||
|
||||
module.exports = server;
|
||||
module.exports = server;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user