mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-10 06:34:41 +02:00
Pardon the noise. More tab to space conversion!
This commit is contained in:
parent
c3635bb26b
commit
1d8be6b014
128 changed files with 8017 additions and 8017 deletions
|
@ -1,25 +1,25 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const User = require('./user.js');
|
||||
const Config = require('./config.js').get;
|
||||
const Log = require('./logger.js').log;
|
||||
const { getAddressedToInfo } = require('./mail_util.js');
|
||||
const Message = require('./message.js');
|
||||
// ENiGMA½
|
||||
const User = require('./user.js');
|
||||
const Config = require('./config.js').get;
|
||||
const Log = require('./logger.js').log;
|
||||
const { getAddressedToInfo } = require('./mail_util.js');
|
||||
const Message = require('./message.js');
|
||||
|
||||
// deps
|
||||
const fs = require('graceful-fs');
|
||||
// deps
|
||||
const fs = require('graceful-fs');
|
||||
|
||||
exports.validateNonEmpty = validateNonEmpty;
|
||||
exports.validateMessageSubject = validateMessageSubject;
|
||||
exports.validateUserNameAvail = validateUserNameAvail;
|
||||
exports.validateUserNameExists = validateUserNameExists;
|
||||
exports.validateUserNameOrRealNameExists = validateUserNameOrRealNameExists;
|
||||
exports.validateGeneralMailAddressedTo = validateGeneralMailAddressedTo;
|
||||
exports.validateEmailAvail = validateEmailAvail;
|
||||
exports.validateBirthdate = validateBirthdate;
|
||||
exports.validatePasswordSpec = validatePasswordSpec;
|
||||
exports.validateNonEmpty = validateNonEmpty;
|
||||
exports.validateMessageSubject = validateMessageSubject;
|
||||
exports.validateUserNameAvail = validateUserNameAvail;
|
||||
exports.validateUserNameExists = validateUserNameExists;
|
||||
exports.validateUserNameOrRealNameExists = validateUserNameOrRealNameExists;
|
||||
exports.validateGeneralMailAddressedTo = validateGeneralMailAddressedTo;
|
||||
exports.validateEmailAvail = validateEmailAvail;
|
||||
exports.validateBirthdate = validateBirthdate;
|
||||
exports.validatePasswordSpec = validatePasswordSpec;
|
||||
|
||||
function validateNonEmpty(data, cb) {
|
||||
return cb(data && data.length > 0 ? null : new Error('Field cannot be empty'));
|
||||
|
@ -34,11 +34,11 @@ function validateUserNameAvail(data, cb) {
|
|||
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
|
||||
// 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 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'));
|
||||
|
@ -47,9 +47,9 @@ function validateUserNameAvail(data, cb) {
|
|||
} 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
|
||||
// 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
|
||||
if(!err) { // err is null if we succeeded -- meaning this user exists already
|
||||
return cb(new Error('Username unavailable'));
|
||||
}
|
||||
|
||||
|
@ -83,11 +83,11 @@ function validateUserNameOrRealNameExists(data, cb) {
|
|||
|
||||
function validateGeneralMailAddressedTo(data, cb) {
|
||||
//
|
||||
// Allow any supported addressing:
|
||||
// - Local username or real name
|
||||
// - Supported remote flavors such as FTN, email, ...
|
||||
// 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.
|
||||
// :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) {
|
||||
|
@ -99,17 +99,17 @@ function validateGeneralMailAddressedTo(data, cb) {
|
|||
|
||||
function validateEmailAvail(data, cb) {
|
||||
//
|
||||
// This particular method allows empty data - e.g. no email entered
|
||||
// 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.
|
||||
// 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
|
||||
// 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)) {
|
||||
|
@ -129,7 +129,7 @@ function validateEmailAvail(data, cb) {
|
|||
|
||||
|
||||
function validateBirthdate(data, cb) {
|
||||
// :TODO: check for dates in the future, or > reasonable values
|
||||
// :TODO: check for dates in the future, or > reasonable values
|
||||
return cb(isNaN(Date.parse(data)) ? new Error('Invalid birthdate') : null);
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ function validatePasswordSpec(data, cb) {
|
|||
return cb(new Error('Password too short'));
|
||||
}
|
||||
|
||||
// check badpass, if avail
|
||||
// check badpass, if avail
|
||||
fs.readFile(config.users.badPassFile, 'utf8', (err, passwords) => {
|
||||
if(err) {
|
||||
Log.warn( { error : err.message }, 'Cannot read bad pass file');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue