diff --git a/controllers/user.js b/controllers/user.js index 1c0f0bfca2..51e3d21eb8 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -192,11 +192,9 @@ exports.checkUniqueUsername = function(req, res) { */ exports.checkExistingUsername = function(req, res) { User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) { - if (data == 1) { - debug('sending false back') + if (data === 1) { return res.send(true); } else { - debug('sending true back') return res.send(false); } }); diff --git a/public/js/main.js b/public/js/main.js index 2d8d85b29e..754c41a728 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -194,15 +194,12 @@ profileValidation.directive('existingUsername', function($http) { if (element.val().length > 0) { ngModel.$setValidity('exists', false); } else { + $('#completed-with').removeClass('ng-dirty'); ngModel.$setPristine(); } if (element.val()) { $http.get("/api/checkExistingUsername/" + element.val()).success(function (data) { - if (element.val() == scope.existingUsername) { - ngModel.$setValidity('exists', false); - } else if (data) { - ngModel.$setValidity('exists', true); - } + ngModel.$setValidity('exists', data); }); } });