Add validateGeneralMailAddressedTo()
This commit is contained in:
parent
149f8bd9f5
commit
9a00b3eb15
|
@ -2,9 +2,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const User = require('./user.js');
|
const User = require('./user.js');
|
||||||
const Config = require('./config.js').config;
|
const Config = require('./config.js').config;
|
||||||
const Log = require('./logger.js').log;
|
const Log = require('./logger.js').log;
|
||||||
|
const { getAddressedToInfo } = require('./mail_util.js');
|
||||||
|
const Message = require('./message.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const fs = require('graceful-fs');
|
const fs = require('graceful-fs');
|
||||||
|
@ -14,6 +16,7 @@ exports.validateMessageSubject = validateMessageSubject;
|
||||||
exports.validateUserNameAvail = validateUserNameAvail;
|
exports.validateUserNameAvail = validateUserNameAvail;
|
||||||
exports.validateUserNameExists = validateUserNameExists;
|
exports.validateUserNameExists = validateUserNameExists;
|
||||||
exports.validateUserNameOrRealNameExists = validateUserNameOrRealNameExists;
|
exports.validateUserNameOrRealNameExists = validateUserNameOrRealNameExists;
|
||||||
|
exports.validateGeneralMailAddressedTo = validateGeneralMailAddressedTo;
|
||||||
exports.validateEmailAvail = validateEmailAvail;
|
exports.validateEmailAvail = validateEmailAvail;
|
||||||
exports.validateBirthdate = validateBirthdate;
|
exports.validateBirthdate = validateBirthdate;
|
||||||
exports.validatePasswordSpec = validatePasswordSpec;
|
exports.validatePasswordSpec = validatePasswordSpec;
|
||||||
|
@ -55,30 +58,44 @@ function validateUserNameAvail(data, cb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateUserNameExists(data, cb) {
|
const invalidUserNameError = () => new Error('Invalid username');
|
||||||
const invalidUserNameError = new Error('Invalid username');
|
|
||||||
|
|
||||||
|
function validateUserNameExists(data, cb) {
|
||||||
if(0 === data.length) {
|
if(0 === data.length) {
|
||||||
return cb(invalidUserNameError);
|
return cb(invalidUserNameError());
|
||||||
}
|
}
|
||||||
|
|
||||||
User.getUserIdAndName(data, (err) => {
|
User.getUserIdAndName(data, (err) => {
|
||||||
return cb(err ? invalidUserNameError : null);
|
return cb(err ? invalidUserNameError() : null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateUserNameOrRealNameExists(data, cb) {
|
function validateUserNameOrRealNameExists(data, cb) {
|
||||||
const invalidUserNameError = new Error('Invalid username');
|
|
||||||
|
|
||||||
if(0 === data.length) {
|
if(0 === data.length) {
|
||||||
return cb(invalidUserNameError);
|
return cb(invalidUserNameError());
|
||||||
}
|
}
|
||||||
|
|
||||||
User.getUserIdAndNameByLookup(data, err => {
|
User.getUserIdAndNameByLookup(data, err => {
|
||||||
return cb(err ? invalidUserNameError : null);
|
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);
|
||||||
|
|
||||||
|
if(Message.AddressFlavor.FTN === addressedToInfo.flavor) {
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateUserNameOrRealNameExists(data, cb);
|
||||||
|
}
|
||||||
|
|
||||||
function validateEmailAvail(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
|
||||||
|
|
Loading…
Reference in New Issue