mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-10 14:44:40 +02:00
ENiGMA 1/2 WILL USE SPACES FROM THIS POINT ON VS TABS
* Really just to make GitHub formatting happy. Arg.
This commit is contained in:
parent
5ddf04c882
commit
e9787cee3e
135 changed files with 27397 additions and 27397 deletions
|
@ -22,135 +22,135 @@ exports.validateBirthdate = validateBirthdate;
|
|||
exports.validatePasswordSpec = validatePasswordSpec;
|
||||
|
||||
function validateNonEmpty(data, cb) {
|
||||
return cb(data && data.length > 0 ? null : new Error('Field cannot be empty'));
|
||||
return cb(data && data.length > 0 ? null : new Error('Field cannot be empty'));
|
||||
}
|
||||
|
||||
function validateMessageSubject(data, cb) {
|
||||
return cb(data && data.length > 1 ? null : new Error('Subject too short'));
|
||||
return cb(data && data.length > 1 ? null : new Error('Subject too short'));
|
||||
}
|
||||
|
||||
function validateUserNameAvail(data, cb) {
|
||||
const config = Config();
|
||||
if(!data || data.length < config.users.usernameMin) {
|
||||
cb(new Error('Username too short'));
|
||||
} else if(data.length > config.users.usernameMax) {
|
||||
// generally should be unreached due to view restraints
|
||||
return cb(new Error('Username too long'));
|
||||
} else {
|
||||
const usernameRegExp = new RegExp(config.users.usernamePattern);
|
||||
const invalidNames = config.users.newUserNames + config.users.badUserNames;
|
||||
const config = Config();
|
||||
if(!data || data.length < config.users.usernameMin) {
|
||||
cb(new Error('Username too short'));
|
||||
} else if(data.length > config.users.usernameMax) {
|
||||
// generally should be unreached due to view restraints
|
||||
return cb(new Error('Username too long'));
|
||||
} else {
|
||||
const usernameRegExp = new RegExp(config.users.usernamePattern);
|
||||
const invalidNames = config.users.newUserNames + config.users.badUserNames;
|
||||
|
||||
if(!usernameRegExp.test(data)) {
|
||||
return cb(new Error('Username contains invalid characters'));
|
||||
} else if(invalidNames.indexOf(data.toLowerCase()) > -1) {
|
||||
return cb(new Error('Username is blacklisted'));
|
||||
} else if(/^[0-9]+$/.test(data)) {
|
||||
return cb(new Error('Username cannot be a number'));
|
||||
} else {
|
||||
// a new user name cannot be an existing user name or an existing real name
|
||||
User.getUserIdAndNameByLookup(data, function userIdAndName(err) {
|
||||
if(!err) { // err is null if we succeeded -- meaning this user exists already
|
||||
return cb(new Error('Username unavailable'));
|
||||
}
|
||||
if(!usernameRegExp.test(data)) {
|
||||
return cb(new Error('Username contains invalid characters'));
|
||||
} else if(invalidNames.indexOf(data.toLowerCase()) > -1) {
|
||||
return cb(new Error('Username is blacklisted'));
|
||||
} else if(/^[0-9]+$/.test(data)) {
|
||||
return cb(new Error('Username cannot be a number'));
|
||||
} else {
|
||||
// a new user name cannot be an existing user name or an existing real name
|
||||
User.getUserIdAndNameByLookup(data, function userIdAndName(err) {
|
||||
if(!err) { // err is null if we succeeded -- meaning this user exists already
|
||||
return cb(new Error('Username unavailable'));
|
||||
}
|
||||
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const invalidUserNameError = () => new Error('Invalid username');
|
||||
|
||||
function validateUserNameExists(data, cb) {
|
||||
if(0 === data.length) {
|
||||
return cb(invalidUserNameError());
|
||||
}
|
||||
if(0 === data.length) {
|
||||
return cb(invalidUserNameError());
|
||||
}
|
||||
|
||||
User.getUserIdAndName(data, (err) => {
|
||||
return cb(err ? invalidUserNameError() : null);
|
||||
});
|
||||
User.getUserIdAndName(data, (err) => {
|
||||
return cb(err ? invalidUserNameError() : null);
|
||||
});
|
||||
}
|
||||
|
||||
function validateUserNameOrRealNameExists(data, cb) {
|
||||
if(0 === data.length) {
|
||||
return cb(invalidUserNameError());
|
||||
}
|
||||
if(0 === data.length) {
|
||||
return cb(invalidUserNameError());
|
||||
}
|
||||
|
||||
User.getUserIdAndNameByLookup(data, err => {
|
||||
return cb(err ? invalidUserNameError() : null);
|
||||
});
|
||||
User.getUserIdAndNameByLookup(data, err => {
|
||||
return cb(err ? invalidUserNameError() : null);
|
||||
});
|
||||
}
|
||||
|
||||
function validateGeneralMailAddressedTo(data, cb) {
|
||||
//
|
||||
// Allow any supported addressing:
|
||||
// - Local username or real name
|
||||
// - Supported remote flavors such as FTN, email, ...
|
||||
//
|
||||
// :TODO: remove hard-coded FTN check here. We need a decent way to register global supported flavors with modules.
|
||||
const addressedToInfo = getAddressedToInfo(data);
|
||||
//
|
||||
// Allow any supported addressing:
|
||||
// - Local username or real name
|
||||
// - Supported remote flavors such as FTN, email, ...
|
||||
//
|
||||
// :TODO: remove hard-coded FTN check here. We need a decent way to register global supported flavors with modules.
|
||||
const addressedToInfo = getAddressedToInfo(data);
|
||||
|
||||
if(Message.AddressFlavor.FTN === addressedToInfo.flavor) {
|
||||
return cb(null);
|
||||
}
|
||||
if(Message.AddressFlavor.FTN === addressedToInfo.flavor) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
return validateUserNameOrRealNameExists(data, cb);
|
||||
return validateUserNameOrRealNameExists(data, cb);
|
||||
}
|
||||
|
||||
function validateEmailAvail(data, cb) {
|
||||
//
|
||||
// This particular method allows empty data - e.g. no email entered
|
||||
//
|
||||
if(!data || 0 === data.length) {
|
||||
return cb(null);
|
||||
}
|
||||
//
|
||||
// This particular method allows empty data - e.g. no email entered
|
||||
//
|
||||
if(!data || 0 === data.length) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
//
|
||||
// Otherwise, it must be a valid email. We'll be pretty lose here, like
|
||||
// the HTML5 spec.
|
||||
//
|
||||
// See http://stackoverflow.com/questions/7786058/find-the-regex-used-by-html5-forms-for-validation
|
||||
//
|
||||
const emailRegExp = /[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9-]+(.[a-z0-9-]+)*/;
|
||||
if(!emailRegExp.test(data)) {
|
||||
return cb(new Error('Invalid email address'));
|
||||
}
|
||||
//
|
||||
// Otherwise, it must be a valid email. We'll be pretty lose here, like
|
||||
// the HTML5 spec.
|
||||
//
|
||||
// See http://stackoverflow.com/questions/7786058/find-the-regex-used-by-html5-forms-for-validation
|
||||
//
|
||||
const emailRegExp = /[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9-]+(.[a-z0-9-]+)*/;
|
||||
if(!emailRegExp.test(data)) {
|
||||
return cb(new Error('Invalid email address'));
|
||||
}
|
||||
|
||||
User.getUserIdsWithProperty('email_address', data, function userIdsWithEmail(err, uids) {
|
||||
if(err) {
|
||||
return cb(new Error('Internal system error'));
|
||||
} else if(uids.length > 0) {
|
||||
return cb(new Error('Email address not unique'));
|
||||
}
|
||||
User.getUserIdsWithProperty('email_address', data, function userIdsWithEmail(err, uids) {
|
||||
if(err) {
|
||||
return cb(new Error('Internal system error'));
|
||||
} else if(uids.length > 0) {
|
||||
return cb(new Error('Email address not unique'));
|
||||
}
|
||||
|
||||
return cb(null);
|
||||
});
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function validateBirthdate(data, cb) {
|
||||
// :TODO: check for dates in the future, or > reasonable values
|
||||
return cb(isNaN(Date.parse(data)) ? new Error('Invalid birthdate') : null);
|
||||
// :TODO: check for dates in the future, or > reasonable values
|
||||
return cb(isNaN(Date.parse(data)) ? new Error('Invalid birthdate') : null);
|
||||
}
|
||||
|
||||
function validatePasswordSpec(data, cb) {
|
||||
const config = Config();
|
||||
if(!data || data.length < config.users.passwordMin) {
|
||||
return cb(new Error('Password too short'));
|
||||
}
|
||||
const config = Config();
|
||||
if(!data || data.length < config.users.passwordMin) {
|
||||
return cb(new Error('Password too short'));
|
||||
}
|
||||
|
||||
// check badpass, if avail
|
||||
fs.readFile(config.users.badPassFile, 'utf8', (err, passwords) => {
|
||||
if(err) {
|
||||
Log.warn( { error : err.message }, 'Cannot read bad pass file');
|
||||
return cb(null);
|
||||
}
|
||||
// check badpass, if avail
|
||||
fs.readFile(config.users.badPassFile, 'utf8', (err, passwords) => {
|
||||
if(err) {
|
||||
Log.warn( { error : err.message }, 'Cannot read bad pass file');
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
passwords = passwords.toString().split(/\r\n|\n/g);
|
||||
if(passwords.includes(data)) {
|
||||
return cb(new Error('Password is too common'));
|
||||
}
|
||||
passwords = passwords.toString().split(/\r\n|\n/g);
|
||||
if(passwords.includes(data)) {
|
||||
return cb(new Error('Password is too common'));
|
||||
}
|
||||
|
||||
return cb(null);
|
||||
});
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue