This commit is contained in:
Barış Soner Uşaklı
2017-05-08 13:49:35 -04:00
481 changed files with 1430 additions and 654 deletions

View File

@@ -17,7 +17,7 @@ var translator = require('../translator');
var sockets = require('../socket.io');
var authenticationController = {};
var authenticationController = module.exports;
authenticationController.register = function (req, res) {
var registrationType = meta.config.registrationType || 'normal';
@@ -345,21 +345,21 @@ authenticationController.localLogin = function (req, username, password, next) {
var uid;
var userData = {};
if (!password || !utils.isPasswordValid(password)) {
return next(new Error('[[error:invalid-password]]'));
}
if (password.length > 4096) {
return next(new Error('[[error:password-too-long]]'));
}
async.waterfall([
function (next) {
user.isPasswordValid(password, next);
},
function (next) {
user.getUidByUserslug(userslug, next);
},
function (_uid, next) {
if (!_uid) {
return next(new Error('[[error:no-user]]'));
}
uid = _uid;
user.auth.logAttempt(uid, req.ip, next);
},
function (next) {
async.parallel({
userData: function (next) {
db.getObjectFields('user:' + uid, ['password', 'passwordExpiry'], next);
@@ -381,19 +381,18 @@ authenticationController.localLogin = function (req, username, password, next) {
return next(new Error('[[error:local-login-disabled]]'));
}
if (!userData || !userData.password) {
return next(new Error('[[error:invalid-user-data]]'));
}
if (result.banned) {
return banUser(uid, next);
}
user.auth.logAttempt(uid, req.ip, next);
},
function (next) {
Password.compare(password, userData.password, next);
},
function (passwordMatch, next) {
if (!passwordMatch) {
return next(new Error('[[error:invalid-password]]'));
return next(new Error('[[error:invalid-login-credentials]]'));
}
user.auth.clearLoginAttempts(uid);
next(null, userData, '[[success:authentication-successful]]');
@@ -447,5 +446,3 @@ function banUser(uid, next) {
}
});
}
module.exports = authenticationController;