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);
} else {
// 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) {
callback(err);
} else {

View File

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

View File

@ -9,13 +9,14 @@ const Log = require('./logger.js').log;
// deps
const fs = require('graceful-fs');
exports.validateNonEmpty = validateNonEmpty;
exports.validateMessageSubject = validateMessageSubject;
exports.validateUserNameAvail = validateUserNameAvail;
exports.validateUserNameExists = validateUserNameExists;
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.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'));
@ -42,7 +43,8 @@ function validateUserNameAvail(data, cb) {
} else if(/^[0-9]+$/.test(data)) {
return cb(new Error('Username cannot be a number'));
} 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
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) {
//
// This particular method allows empty data - e.g. no email entered