Lookup username and real name in various scenarios
This commit is contained in:
parent
f967ce1ce6
commit
ab12fb5d79
|
@ -413,13 +413,13 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
|
|||
function populateLocalUserInfo(callback) {
|
||||
if(self.isPrivateMail()) {
|
||||
self.message.setLocalFromUserId(self.client.user.userId);
|
||||
|
||||
|
||||
if(self.toUserId > 0) {
|
||||
self.message.setLocalToUserId(self.toUserId);
|
||||
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 {
|
||||
|
|
|
@ -112,7 +112,7 @@ Message.FtnPropertyNames = {
|
|||
FtnDestZone : 'ftn_dest_zone',
|
||||
FtnOrigPoint : 'ftn_orig_point',
|
||||
FtnDestPoint : 'ftn_dest_point',
|
||||
|
||||
|
||||
FtnAttribute : 'ftn_attribute',
|
||||
|
||||
FtnTearLine : 'ftn_tear_line', // http://ftsc.org/docs/fts-0004.001
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,11 +43,12 @@ 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'));
|
||||
}
|
||||
|
||||
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue