Lookup username and real name in various scenarios

This commit is contained in:
Bryan Ashby 2018-01-05 22:03:33 -07:00
parent f967ce1ce6
commit ab12fb5d79
5 changed files with 28 additions and 14 deletions

View File

@ -419,7 +419,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
callback(null); callback(null);
} else { } else {
// we need to look it up // we need to look it up
User.getUserIdAndName(self.message.toUserName, function userInfo(err, toUserId) { User.getUserIdAndNameByLookup(self.message.toUserName, function userInfo(err, toUserId) {
if(err) { if(err) {
callback(err); callback(err);
} else { } else {

View File

@ -55,7 +55,7 @@ function areaFix() {
const User = require('../user.js'); const User = require('../user.js');
if(argv.from) { if(argv.from) {
User.getUserIdAndName(argv.from, (err, userId, fromName) => { User.getUserIdAndNameByLookup(argv.from, (err, userId, fromName) => {
if(err) { if(err) {
return callback(null, ftnAddr, argv.from, 0); return callback(null, ftnAddr, argv.from, 0);
} }

View File

@ -13,6 +13,7 @@ exports.validateNonEmpty = validateNonEmpty;
exports.validateMessageSubject = validateMessageSubject; exports.validateMessageSubject = validateMessageSubject;
exports.validateUserNameAvail = validateUserNameAvail; exports.validateUserNameAvail = validateUserNameAvail;
exports.validateUserNameExists = validateUserNameExists; exports.validateUserNameExists = validateUserNameExists;
exports.validateUserNameOrRealNameExists = validateUserNameOrRealNameExists;
exports.validateEmailAvail = validateEmailAvail; exports.validateEmailAvail = validateEmailAvail;
exports.validateBirthdate = validateBirthdate; exports.validateBirthdate = validateBirthdate;
exports.validatePasswordSpec = validatePasswordSpec; exports.validatePasswordSpec = validatePasswordSpec;
@ -42,7 +43,8 @@ function validateUserNameAvail(data, cb) {
} else if(/^[0-9]+$/.test(data)) { } else if(/^[0-9]+$/.test(data)) {
return cb(new Error('Username cannot be a number')); return cb(new Error('Username cannot be a number'));
} else { } else {
User.getUserIdAndName(data, function userIdAndName(err) { // 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')); return cb(new Error('Username unavailable'));
} }
@ -65,6 +67,18 @@ function validateUserNameExists(data, cb) {
}); });
} }
function validateUserNameOrRealNameExists(data, cb) {
const invalidUserNameError = new Error('Invalid username');
if(0 === data.length) {
return cb(invalidUserNameError);
}
User.getUserIdAndNameByLookup(data, err => {
return cb(err ? invalidUserNameError : null);
});
}
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