From 87c67466768ea37cb858c4e82cf1a0a2389fd145 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 25 Jul 2016 01:01:14 -0600 Subject: [PATCH] validateUserNameExists() --- core/system_view_validate.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/system_view_validate.js b/core/system_view_validate.js index 90fdab15..4508f18a 100644 --- a/core/system_view_validate.js +++ b/core/system_view_validate.js @@ -4,6 +4,7 @@ var Config = require('./config.js').config; exports.validateNonEmpty = validateNonEmpty; exports.validateMessageSubject = validateMessageSubject; exports.validateUserNameAvail = validateUserNameAvail; +exports.validateUserNameExists = validateUserNameExists; exports.validateEmailAvail = validateEmailAvail; exports.validateBirthdate = validateBirthdate; exports.validatePasswordSpec = validatePasswordSpec; @@ -42,6 +43,18 @@ function validateUserNameAvail(data, cb) { } } +function validateUserNameExists(data, cb) { + const invalidUserNameError = new Error('Invalid username'); + + if(0 === data.length) { + return cb(invalidUserNameError); + } + + user.getUserIdAndName(data, (err) => { + return cb(err ? invalidUserNameError : null); + }); +} + function validateEmailAvail(data, cb) { // // This particular method allows empty data - e.g. no email entered