|
|
@ -6,6 +6,7 @@
|
|
|
|
nconf = require('nconf'),
|
|
|
|
nconf = require('nconf'),
|
|
|
|
bcrypt = require('bcryptjs'),
|
|
|
|
bcrypt = require('bcryptjs'),
|
|
|
|
winston = require('winston'),
|
|
|
|
winston = require('winston'),
|
|
|
|
|
|
|
|
async = require('async'),
|
|
|
|
|
|
|
|
|
|
|
|
meta = require('./../meta'),
|
|
|
|
meta = require('./../meta'),
|
|
|
|
user = require('./../user'),
|
|
|
|
user = require('./../user'),
|
|
|
@ -30,13 +31,10 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function login(req, res, next) {
|
|
|
|
function login(req, res, next) {
|
|
|
|
if(meta.config.allowLocalLogin !== undefined && parseInt(meta.config.allowLocalLogin, 10) === 0) {
|
|
|
|
var continueLogin = function() {
|
|
|
|
return res.send(404);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
passport.authenticate('local', function(err, userData, info) {
|
|
|
|
passport.authenticate('local', function(err, userData, info) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
return next(err);
|
|
|
|
return res.json(403, err.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!userData) {
|
|
|
|
if (!userData) {
|
|
|
@ -63,6 +61,23 @@
|
|
|
|
res.json(200, info);
|
|
|
|
res.json(200, info);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})(req, res, next);
|
|
|
|
})(req, res, next);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(meta.config.allowLocalLogin !== undefined && parseInt(meta.config.allowLocalLogin, 10) === 0) {
|
|
|
|
|
|
|
|
return res.send(404);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.body.username && utils.isEmailValid(req.body.username)) {
|
|
|
|
|
|
|
|
user.getUsernameByEmail(req.body.username, function(err, username) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return next(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
req.body.username = username ? username : req.body.username;
|
|
|
|
|
|
|
|
continueLogin();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
continueLogin();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function register(req, res) {
|
|
|
|
function register(req, res) {
|
|
|
@ -140,19 +155,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
app.post('/logout', logout);
|
|
|
|
app.post('/logout', logout);
|
|
|
|
app.post('/register', register);
|
|
|
|
app.post('/register', register);
|
|
|
|
app.post('/login', function(req, res, next) {
|
|
|
|
app.post('/login', login);
|
|
|
|
if (req.body.username && utils.isEmailValid(req.body.username)) {
|
|
|
|
|
|
|
|
user.getUsernameByEmail(req.body.username, function(err, username) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return next(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
req.body.username = username ? username : req.body.username;
|
|
|
|
|
|
|
|
login(req, res, next);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
login(req, res, next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|