var bodyParser = require('body-parser');
var bcrypt = require('bcryptjs');
router.post('/addUsers', bodyParser.json(), function (req, res, next) {
logger.info('API:"post /api/users/addUsers" accessed.');
var password = req.body.password ? req.body.password : '';
var username = req.body.username ? req.body.username : '';
if (!username) {
return res.status(200).json({ code: 1, msg: "The username is empty", data: null });
}
validate.checkPassword(data, password, function (err, rows) {
if (err) {
logger.error("Error checking password!error: ", err);
return res.status(200).json({ code: 1, msg: "Error checking password! error: " + err, data: null });
} else {
validate.checkUserName(username, function (err, rows) {
if (err) {
logger.error("Error checking password!error: ", err);
return res.status(200).json({ code: 1, msg: "Error checking password! error: " + err, data: null });
} else {
var salt = bcrypt.genSaltSync(10);
var enc_pwd = bcrypt.hashSync(password, salt);
....
...
...
}
}