mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-27 09:01:23 +01:00
closes #6855
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
"loginDays": 14,
|
||||
"loginSeconds": 0,
|
||||
"loginAttempts": 5,
|
||||
"lockoutDuration": 60,
|
||||
"adminReloginDuration": 60,
|
||||
"postDelay": 10,
|
||||
"initialPostDelay": 10,
|
||||
|
||||
@@ -19,18 +19,24 @@ Meta.config = {};
|
||||
function deserialize(config) {
|
||||
var deserialized = {};
|
||||
Object.keys(config).forEach(function (key) {
|
||||
if (typeof config[key] !== 'string') {
|
||||
deserialized[key] = config[key];
|
||||
return;
|
||||
}
|
||||
const defaultType = typeof defaults[key];
|
||||
const type = typeof config[key];
|
||||
|
||||
var number = parseFloat(config[key]);
|
||||
if (!isNaN(number) && isFinite(config[key])) {
|
||||
deserialized[key] = number;
|
||||
if (defaultType === 'string' && type === 'number') {
|
||||
deserialized[key] = String(config[key]);
|
||||
} else if (defaultType === 'number' && type === 'string') {
|
||||
const number = parseFloat(config[key]);
|
||||
if (!isNaN(number) && isFinite(config[key])) {
|
||||
deserialized[key] = number;
|
||||
} else {
|
||||
deserialized[key] = defaults[key];
|
||||
}
|
||||
} else if (config[key] === 'true') {
|
||||
deserialized[key] = true;
|
||||
} else if (config[key] === 'false') {
|
||||
deserialized[key] = false;
|
||||
} else if (config[key] === null) {
|
||||
deserialized[key] = defaults[key];
|
||||
} else {
|
||||
deserialized[key] = config[key];
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@ module.exports = function (User) {
|
||||
}
|
||||
db.increment('loginAttempts:' + uid, next);
|
||||
},
|
||||
function (attemps, next) {
|
||||
if (attemps <= meta.config.loginAttempts) {
|
||||
function (attempts, next) {
|
||||
if (attempts <= meta.config.loginAttempts) {
|
||||
return db.pexpire('loginAttempts:' + uid, 1000 * 60 * 60, callback);
|
||||
}
|
||||
// Lock out the account
|
||||
db.set('lockout:' + uid, '', next);
|
||||
},
|
||||
function (next) {
|
||||
var duration = 1000 * 60 * (meta.config.lockoutDuration || 60);
|
||||
var duration = 1000 * 60 * meta.config.lockoutDuration;
|
||||
|
||||
db.delete('loginAttempts:' + uid);
|
||||
db.pexpire('lockout:' + uid, duration);
|
||||
|
||||
68
test/meta.js
68
test/meta.js
@@ -111,6 +111,72 @@ describe('meta', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the correct type and default value', function (done) {
|
||||
meta.configs.set('loginAttempts', '', function (err) {
|
||||
assert.ifError(err);
|
||||
meta.configs.get('loginAttempts', function (err, value) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(value, 5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the correct type and correct value', function (done) {
|
||||
meta.configs.set('loginAttempts', '0', function (err) {
|
||||
assert.ifError(err);
|
||||
meta.configs.get('loginAttempts', function (err, value) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(value, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the correct value', function (done) {
|
||||
meta.configs.set('title', 123, function (err) {
|
||||
assert.ifError(err);
|
||||
meta.configs.get('title', function (err, value) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(value, '123');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the correct value', function (done) {
|
||||
meta.configs.set('title', 0, function (err) {
|
||||
assert.ifError(err);
|
||||
meta.configs.get('title', function (err, value) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(value, '0');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the correct value', function (done) {
|
||||
meta.configs.set('title', '', function (err) {
|
||||
assert.ifError(err);
|
||||
meta.configs.get('title', function (err, value) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(value, '');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should use default value if value is null', function (done) {
|
||||
meta.configs.set('teaserPost', null, function (err) {
|
||||
assert.ifError(err);
|
||||
meta.configs.get('teaserPost', function (err, value) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(value, 'last-reply');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if field is invalid', function (done) {
|
||||
meta.configs.set('', 'someValue', function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
@@ -185,7 +251,7 @@ describe('meta', function () {
|
||||
assert.ifError(err);
|
||||
meta.configs.getFields(['stringField'], function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(data.stringField, 123);
|
||||
assert.strictEqual(data.stringField, '123');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user